Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

I am in need of help doing a FOR /F Do loop in a CMD Batch

Mar 14, 2012 2:50AM PDT

I am in need of help doing a FOR /F Do loop in a CMD Batch script.

I am trying to write a batch script that will ping all IP addresses in a host file except for an IP address taht starts with 127 and skip all commented lines in the hostfile or that start with a #.

my current code will ping the first word/string in every uncommented line, so I am halfway there. However I can't figure out how to compare the first 4 characters in the word/sting to 127. and have it skip it if starts with those characters.

Here is my working code. Any help will be appreciated.

[code]
@ECHO off
setlocal EnableExtensions EnableDelayedExpansion

DEL C:\temp\Pings.txt

ECHO. > C:\temp\Pings.txt

For /F "eol=# tokens=1" %%A in (c:\temp\TESThost) do ECHO PING -a "%%A" && ECHO. >> C:\temp\Pings.txt && ECHO. >> C:\temp\Pings.txt && ECHO PING -a "%%A" >> C:\temp\Pings.txt && PING -a "%%A" >> C:\temp\Pings.txt && ECHO ---------------------------------------------------------------- >> C:\temp\Pings.txt
[/code]

Discussion is locked

- Collapse -
Answer
Wrong problem statement.
Mar 24, 2012 1:49AM PDT
- Collapse -
Answer
Odd to limit ourselves to batch.
Mar 25, 2012 3:01AM PDT