0

I have some batch tests which dump data files of the following format in a folder. Each test dumps 1 file and the file name is a generic serial number. I would like to generate a list of all failed log filenames with the Testname.

I can use xargs but unable to print out the Testname. Following script dumps every log file, and it's workable though I would like a better solution.

grep 'Fail\|Testname' *.log

Sample File test_0123.log

[other log of 20MB]
* Result : Pass/Fail
* Testname : test_example_rsa_key_gen
[other log  and trailer]
  • Is the log filename the value of the field Testname? And what is the Testcase in grep 'Fail\|Testcase' *.log? – Niko Gambt Jan 23 at 5:20
  • Is the content of each log file just the two lines with Result and Testname, or are there more lines? – finswimmer Jan 23 at 5:29
  • That's a typo. Each file contains only one testname and one verdict, but thousands of lines before and after those two lines. This line works now. Thank you. grep -A1 'Fail' *.log | grep 'Testcase'. – kelvin Jan 23 at 6:52
0
perl -0777ne 'if ( /Result : Fail/ and /Testname : (\S+)/ ) { print "filename: $ARGV; testname: $1" }'  *.log
  • Thank you! I got a Out of memory error with Perl. The log files is double digit MB each. A shell script like grep would be more efficient. – kelvin Jan 23 at 4:26
  • You don't have double digit MB of memory available? Use this: grep -A1 "^..Result : Fail" *.log | grep :..Testname.: – Oh My Goodness Jan 23 at 5:18
  • Yes I do. But there are thousands of log files. I managed to get it done with this: grep -A1 'Fail' *.log | grep 'Testcase' – kelvin Jan 23 at 6:50

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.