Delete lines from log.txt using cmd

September 28, 2011 at 10:41:19
Specs: Windows XP
Hi Guys.

I am looking to get some help with this batch file.

@echo off
@echo Test
@echo:

@echo:
@echo Test POS
@echo:
@echo 10.10.2.201
@echo 10.10.2.202
@echo 10.10.2.203
@echo 10.10.2.204
@echo 10.10.2.207

ECHO %DATE% %TIME% > C:\wol\IPLog.txt

ping -n 3 10.10.2.201 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.202 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.203 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.204 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.207 >> C:\wol\IPLog.txt


C:\wol\wolcmd Mac Address 10.10.2.201 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.202 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.203 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.204 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.207 255.255.255.0 8900

ping -n 2 10.10.1.60 >null

echo: >> C:\wol\IPLog.txt
echo AFTER WOL >> C:\wol\IPLog.txt


ping -n 3 10.10.2.201 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.202 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.203 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.204 >> C:\wol\IPLog.txt
ping -n 3 10.10.2.207 >> C:\wol\IPLog.txt

Exit

I want it to ping the ip before WOL and then wake up pc's and then re ping the ip and log it.

The problem i have it includes all the IP statistics

Ping statistics for 10.10.2.201:

Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

I need some script to remove it.

This batch is schedule task as not to loop it.

Thanks in advance :)


See More: Delete lines from log.txt using cmd

Report •

#1
September 28, 2011 at 14:37:51
Your post is somewhat confusing to me. What are you wanting in the log file if not the results? Let me know and ill make something up for you. Answered a similar post a awhile back.

Report •

#2
September 28, 2011 at 15:36:05
I have the batch working -

What i am looking for is as follows

When the batch starts i want it to to see if an IP Address is Alive and logs it accordlling .

It then runs the WOL regardless of the IP Address outcome.

Then 30 Secs after it finds if the IP Address is alive and logs it.

The way it works at the moment is it logs the ping but is giving me all the Ping Stats which i dont want.

Hope you know what i mean

Thanks


Report •

#3
September 29, 2011 at 13:23:19
I do not know of any way to delete text with a batch file (not to say its not do-able). So I always figure out the variables that I want to keep and extract them to a new file, then delete the old file. You can do this by using FINDSTR. So lets say you want to keep all of the pings, you would make a codes snippet like this:

findstr /x "-n" IPLog.txt >> NewIPLog.txt

this will take all lines that hold "-n" and copies them to the new log. That will take care of all of your pings. The /x is to make it match exactly which is also why we included the n, this way we are not grabbing the "milli-seconds" line. You may want to include another for "echo AFTER WOL >> C:\wol\IPLog.txt" section; ex:

findstr /i after IPLog.txt >> NewIPLog.txt

the /i is to make it NOT case-sensitive. This is the best way I know how to do it. Two lines of code and your all set; maybe one more to delete the other text file. I hope this helps


Report •

Related Solutions

#4
September 29, 2011 at 15:00:55
Thanks dude sounds exactly what i need could you add that to the code in my first post. I would really appricate it :) I would want it in to two sections before and after WOL

Thanks again


Report •

#5
September 29, 2011 at 15:32:18
NOT TESTED

@echo off
@echo Test
@echo:
@echo:
@echo Test POS
@echo:
@echo 10.10.2.201
@echo 10.10.2.202
@echo 10.10.2.203
@echo 10.10.2.204
@echo 10.10.2.207
ECHO %DATE% %TIME% > C:\wol\IPLog.txt
ping -n 3 10.10.2.201 >> C:\wol\temp.txt
ping -n 3 10.10.2.202 >> C:\wol\temp.txt
ping -n 3 10.10.2.203 >> C:\wol\temp.txt
ping -n 3 10.10.2.204 >> C:\wol\temp.txt
ping -n 3 10.10.2.207 >> C:\wol\temp.txt

C:\wol\wolcmd Mac Address 10.10.2.201 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.202 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.203 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.204 255.255.255.0 8900
C:\wol\wolcmd Mac Address 10.10.2.207 255.255.255.0 8900
ping -n 2 10.10.1.60 >null
echo: >> C:\wol\temp.txt
echo AFTER WOL >> C:\wol\temp.txt

ping -n 3 10.10.2.201 >> C:\wol\temp.txt
ping -n 3 10.10.2.202 >> C:\wol\temp.txt
ping -n 3 10.10.2.203 >> C:\wol\temp.txt
ping -n 3 10.10.2.204 >> C:\wol\temp.txt
ping -n 3 10.10.2.207 >> C:\wol\temp.txt

findstr /x "-n" C:\wol\temp.txt >> C:\wol\IPLog.txt
findstr : C:\wol\temp.txt >> C:\wol\IPLog.txt
findstr /i after C:\wol\temp.txt >> C:\wol\IPLog.txt

del C:\wol\temp.txt

Give it a shot. Let me know if it works for ya.


Report •

#6
September 29, 2011 at 15:50:40
Just tried it and it hangs after the WOL, nothing happens. When i change the "-n" to Ping or reply i still get all the statistics.

Thanks


Report •

#7
September 30, 2011 at 13:43:26
try removing the " " from "-n"

Report •

Ask Question