
我有一些批量測試,將以下格式的資料檔案轉儲到資料夾中。每個測試轉儲 1 個文件,文件名是通用序號。我想產生帶有測試名稱的所有失敗日誌檔案名稱的清單。
我可以使用 xargs 但無法列印測試名稱。以下腳本轉儲每個日誌文件,儘管我想要一個更好的解決方案,但它是可行的。
grep '失敗\|測試名稱' *.log
範例檔案 test_0123.log
[other log of 20MB]
* Result : Pass/Fail
* Testname : test_example_rsa_key_gen
[other log and trailer]
答案1
perl -0777ne 'if ( /Result : Fail/ and /Testname : (\S+)/ ) { print "filename: $ARGV; testname: $1" }' *.log