How to search and extract part of string in batch script?

0

I am pretty new to windows batch scripting and am having trouble to search and extract a portion of a string from a text file and display it out. Some samples data are shown below.

The keyword for searching is based on student ID, for example: STUD777012

Appreciate if you could help out.

Thank you very much.


SAMPLE EXPECTED OUTPUT:

STUD777012, return code: 0, Analysis detected no errors

STUD777293, return code: 4, Analysis detected warnings

STUD777086, return code: 8, Analysis detected errors

STUD777099, return code: 0, Analysis detected no errors


SAMPLE LOG DATA:

Compiling STUD777012 to Data Structure 
This is prg version 380.10.20 
This is StudPrg.exe version 6.24 
debug enabled version
StudPrg.exe finished 
prg finished with return code: 0
status:
  Analysis detected no errors

Compiling STUD777293 to Data Structure 
This is prg version 380.10.20 
This is StudPrg.exe version 6.24 
debug enabled version
StudPrg.exe finished
This is StudPrg.exe version 6.24 
debug enabled version
StudPrg.exe finished  
prg finished with return code: 4
status:
  Analysis detected warnings

Compiling STUD777086 to Data Structure 
This is prg version 380.10.20 
This is StudPrg.exe version 6.24 
debug enabled version
StudPrg.exe finished  
This is  StudPrg.exe version 6.24 
debug enabled version
StudPrg.exe finished  
prg finished with return code: 8
status:
  Analysis detected errors

Peter

Posted 2014-08-14T01:07:07.853

Reputation: 1

Answers

0

If you open the file in Notepad++ and do a regex replace (Ctrl+H):

Find what: Compiling (\w+).*?(return code[^\r\n]*).*?(analysis detected.*?)(\n|$)
Replace with: \1 \2 \3

You should get what you want. Make sure you have regex enabled and '. matches new line' set. e.g.

enter image description here

snowdude

Posted 2014-08-14T01:07:07.853

Reputation: 2 560

Hi snowdude, thanks for your help. Appreciated it. However, I'm looking for a windows batch script. Thanks again. – Peter – 2014-08-15T01:09:30.900