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]
3
  • Is the log filename the value of the field Testname? And what is the Testcase in grep 'Fail\|Testcase' *.log? Commented Jan 23, 2019 at 5:20
  • Is the content of each log file just the two lines with Result and Testname, or are there more lines? Commented Jan 23, 2019 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'. Commented Jan 23, 2019 at 6:52

1 Answer 1

0
perl -0777ne 'if ( /Result : Fail/ and /Testname : (\S+)/ ) { print "filename: $ARGV; testname: $1" }'  *.log
3
  • 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. Commented Jan 23, 2019 at 4:26
  • You don't have double digit MB of memory available? Use this: grep -A1 "^..Result : Fail" *.log | grep :..Testname.: Commented Jan 23, 2019 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' Commented Jan 23, 2019 at 6:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.