Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Windows batch script FindStr to search for a string and matching line

$
0
0

Hi Gurus,

I've been having some problem in using FIND or FINDSTR command to find a particular string in a log file and return its output with the matching string along with 1 line above and 1 line below the matching line.

So far, this is the only command that I've tried. I've tried to search online, but couldn't find anything useful.
findstr /n "NETWORK ISSUE DETECTED" c:\Log.txt

Sample log data (Log.txt):
1371524155  Tue Jun 18 10:55:55 2013
1371524160  Tue Jun 18 10:56:00 2013
1371524165  Tue Jun 18 10:56:05 2013
NETWORK ISSUE DETECTED
 1371523243  Tue Jun 18 10:40:43 2013
1371523248  Tue Jun 18 10:40:48 2013
1371523253  Tue Jun 18 10:40:53 2013

Desire output (Example):
1371524160  Mon Jun 10 08:50:01 2013
NETWORK ISSUE DETECTED
 1371523241  Mon Jun 10 08:20:41 2013

1371524165  Tue Jun 18 10:56:05 2013
NETWORK ISSUE DETECTED
 1371523243  Tue Jun 18 10:40:43 2013

There maybe more than 1 occurance of the string "NETWORK ISSUE DETECTED" in the log file as it can contains a lot of data. So the script should be able to handle it and output the multiple result of the searched string as shown in the above example.

Appreciate for your kind help.

Thank you.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>