1.

Solve : Delete lines in txt files that contains an STRING or are BLANK.?

Answer»

Hello,
I run a batch file that pings lots of servers.
I want to compress them in order to be EASY to read and i want to delete blank lines and unwanted lines that contains specific words.

My result is like:

Pinging www.yahoo-ht3.akadns.net [87.248.113.14] with 32 bytes of data:

Reply from 87.248.113.14: bytes=32 TIME=74ms TTL=54
Reply from 87.248.113.14: bytes=32 time=69ms TTL=54

Ping statistics for 87.248.113.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round TRIP times in milli-seconds:
Minimum = 69ms, Maximum = 74ms, Average = 72ms

And I want to be it like:

Pinging www.yahoo-ht3.akadns.net [87.248.113.14] with 32 bytes of data:
Reply from 87.248.113.14: bytes=32 time=74ms TTL=54
Reply from 87.248.113.14: bytes=32 time=69ms TTL=54

Thank you!I always like to see posters get at least one response:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=1*" %%i in ('ping localhost ^| findstr /i /v "statistics Packets Approximate Minimum"') do (
set var=%%i
set var=!var:~0,4!
if /i %%i EQU reply echo %%i %%j
if /i !var! EQU ping echo %%i %%j
)

Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names.

Good luck. Quote from: Sidewinder on December 12, 2008, 06:13:08 AM

Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names.

Thank you for response.
I think I should have said from start that I am an beginer in batch files.
I tried to use your code with my ping but don't works. I think I didn't used properly your code.
Any sugestion of how to set up my pings is welcomed also.

My pings setup now looks like this:

Code: [Select]del ping.log
date/t >>ping.log
time/t >>ping.log
ping -n 2 server1 >> ping.log
ping -n 2 server2 >> ping.log
Because I use it to ping nore than 25 servers at the time, the result log is very log and not easy to read.
Sow I only want to make it easy to read and for that I want to cut out non needed lines.
An DREAM would be, if its possible, to have an result like:

Date
Time
SERVER1 RESPONDING
SERVER2 NOT RESPONDING
SERVER3 RESPONDING
SERVER4 NOT RESPONDING
Code: [Select]@echo off

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING
) else (
echo %%S NOT RESPONDING
)
)
Quote from: Dias de verano on December 13, 2008, 02:08:32 AM
Code: [Select]@echo off

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING
) else (
echo %%S NOT RESPONDING
)
)

Hello,
Sorry for not respondig, but I didn't had ACCES to an computer for several days.
Dias de verano, u'r code is almost perfect. I added only ECHO for having an result.txt but it seems to be an problem at ERRORLEVEL. No MATTER of pinged host the response is always RESPONDING.
Here is the code i used, I cut off the messages for space:

Code: [Select]@echo off

echo 123.123.123.123 > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING >> result.txt
) else (
echo %%S NOT RESPONDING >> result.txt
)
)

My result.txt
123.123.123.123 RESPONDING
www.bbc.co.uk RESPONDING
www.yahoo-ht3.akadns.net RESPONDING
Sorry, I made an oversight.

@echo off
setlocal enabledelayedexpansion

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if !errorlevel! EQU 0 (
echo %%S RESPONDING>>result.txt
) else (
echo %%S NOT RESPONDING>>result.txt
)
)

EXCELENT.
THANK YOU VERY MUCH.


Discussion

No Comment Found