Edit bat file to parse strings and send output to file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ezwicky
Posts: 3
Joined: 02 Feb 2021 12:42

Edit bat file to parse strings and send output to file

#1 Post by ezwicky » 02 Feb 2021 12:49

Hi all,

I have a batch file that pings a list of IP addresses. I need to send only the failed pings to a file.

Here's the batch file:

@Echo OFF

For /F "Usebackq Delims=" %%# in (
"List.txt"
) do (
Echo+
Echo [+] Pinging: %%#

Ping -n 1 "%%#" 1>nul && (
Echo [OK]) || (
Echo [FAILED])
)

Pause&Exit


The output looks like this, just showing two for example:

[+] Pinging: 172.17.219.133
[FAILED]


[+] Pinging: 172.28.145.199
[OK]

I need to edit the batch file to send the lines with the IP address of the failed pings to a file.

Is this possible?

Thanks in advance for your time and advice,

Eric


ezwicky
Posts: 3
Joined: 02 Feb 2021 12:42

Re: Edit bat file to parse strings and send output to file

#3 Post by ezwicky » 02 Feb 2021 17:32

Thanks. I added this line ahead of the For stuff:

>results.txt (

<the rest of the stuff>

)

PAUSE

That created the output file just fine. But I want to refince the output to only show the ones that failed, the two lines like this:

[+] Pinging: 172.17.219.133
[FAILED]

So that I have in the file a list of only those devices that aren't reachable.

ezwicky
Posts: 3
Joined: 02 Feb 2021 12:42

Re: Edit bat file to parse strings and send output to file

#4 Post by ezwicky » 03 Feb 2021 08:01

Never mind, I just use Powershell commands to edit the file to show previous line.

Post Reply