sunhux
asked on
enhance batch script to print previous & next lines of search string
https://stackoverflow.com/questions/17940198/batch-script-to-print-previous-and-next-lines-of-search-string-in-a-text-file
Anyone can help enhance the above such that can pass parameter to it:
Parameter 1: search string
Parameter 2: search file ie log.txt
Parameter 3: number of lines above the found search string to be displayed
Parameter 4: number of lines below the found search string to be displayed
If can highlight (in bold) the search string in the display, will be even better.
If just run the script, it'll display the command syntax on how to use the script.
A VB script is good as well but I don't want a PS script
log.txt:
=====
1 a
2 b
3 c
4 d
5 e
6 f
7 g
When I run the script to search for the string "3 c" for 1 line above & 2 lines below,
it should display:
2 b
3 c <== if possible bold this search string
4 d
5 d
Anyone can help enhance the above such that can pass parameter to it:
Parameter 1: search string
Parameter 2: search file ie log.txt
Parameter 3: number of lines above the found search string to be displayed
Parameter 4: number of lines below the found search string to be displayed
If can highlight (in bold) the search string in the display, will be even better.
If just run the script, it'll display the command syntax on how to use the script.
A VB script is good as well but I don't want a PS script
log.txt:
=====
1 a
2 b
3 c
4 d
5 e
6 f
7 g
When I run the script to search for the string "3 c" for 1 line above & 2 lines below,
it should display:
2 b
3 c <== if possible bold this search string
4 d
5 d
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just saw that you edited the original question.
Since there's no "bold" in console output, I edited the script in my last comment so that the matching lines are now prefixed with a "> ".
Since there's no "bold" in console output, I edited the script in my last comment so that the matching lines are now prefixed with a "> ".
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
> just fixed an issue with the prefix when more than one line of context was specified
Don't understand the above. What's more than 1 line of context specified?
Don't understand the above. What's more than 1 line of context specified?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm also very poor with using PS.
I could locate powershell.exe though. Sorry 1 more requirement:
I'm using virustotal API vt.exe so I'll need the script to do sort of
piping eg:
vt.exe "MD5_hash_value" | your_script "search string" 1 9
If it's not possible to pipe, then I'll just do 2 steps ie
vt.exe "MD5_hash_value" > outpt.txt
your_script "search string" outpt.txt 1 9