Hello,

I want to add sequence number, 1, 2,3, .... in my output file to
identify/sort results by the number.
How can I do it in the batch files below? And how can I assign a line read
from screen after |findstr to a variable, so I
can use the value for the next command?

Thanks
Wensi

I want output like:
1, server1, reply
2, server2, reply
...
no, servern, reply.

Here are my tries:
My example 1: ( problem: how can I add the number)

for /f "tokens=1* delims=" %%i in (servers.txt) do (
echo %%i, >> output.txt
ping -n 1 %%i |findstr /i "reply from timed out unknown" >> output.txt
)

My example 2: (problem: how can I get the number and assign the value to a
variable)
set intNum = 0
for /f "tokens=1* delims=" %%i in (servers.txt) do (
echo intNum, %%i
ping -n 1 %%i |findstr /i "reply from timed out unknown"
set intNum = %intNum& +1
)

Re: Sequence number in batch file by Ray

Ray
Thu Jan 06 19:15:27 CST 2005

You may want to repost this question in
microsoft.public.win2000.cmdprompt.admin.

Ray at home

"Wensi Peng" <wensi_peng@hotmail.com> wrote in message
news:OWlwoME9EHA.2012@TK2MSFTNGP15.phx.gbl...
> Hello,
>
> I want to add sequence number, 1, 2,3, .... in my output file to
> identify/sort results by the number.
> How can I do it in the batch files below? And how can I assign a line read
> from screen after |findstr to a variable, so I
> can use the value for the next command?
>
> Thanks
> Wensi
>
> I want output like:
> 1, server1, reply
> 2, server2, reply
> ...
> no, servern, reply.
>
> Here are my tries:
> My example 1: ( problem: how can I add the number)
>
> for /f "tokens=1* delims=" %%i in (servers.txt) do (
> echo %%i, >> output.txt
> ping -n 1 %%i |findstr /i "reply from timed out unknown" >> output.txt
> )
>
> My example 2: (problem: how can I get the number and assign the value to a
> variable)
> set intNum = 0
> for /f "tokens=1* delims=" %%i in (servers.txt) do (
> echo intNum, %%i
> ping -n 1 %%i |findstr /i "reply from timed out unknown"
> set intNum = %intNum& +1
> )
>
>