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

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

  • Hi snowdude, thanks for your help. Appreciated it. However, I'm looking for a windows batch script. Thanks again. – Peter Aug 15 '14 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.