awk命令打印出包含某个字符串的整行

时间:2017-01-24 03:32:03

标签: awk

output.txt
Test Results 1 PASSED with 2 minutes to process 0 issues
Test Results 2 PASSED with 10 minutes to process 0 issues
Test Results 3 FAILED ERROR 1 issues
Test Results 4 PASSED with 4 minutes to process 0 issues
Test Results 5 FAILED ERROR 3 issues
Test Results 6 PASSED with 19 minutes to process 0 issues

我需要帮助来提出一个awk命令来解析这个文本。我只想列出超过0个问题的行。

所以在这种情况下

Test Results 1 PASSED with 2 minutes to process 0 issues Test Results 5 FAILED ERROR 3 issues

2 个答案:

答案 0 :(得分:1)

试试这个:

$ awk '$(NF-1)' file
Test Results 3 FAILED 1 issues
Test Results 5 FAILED 3 issues

答案 1 :(得分:1)

尝试以下

awk '{if (($0 ~ /[0-9] issues/) && ($(NF-1) != "0")) {print $0}}' output.txt

此处检查文本的问题数量。

可以使用

完成
awk '{if ($0 ~ /[1-9] issues/) {print $0}}' output.txt

如果您确定只有1-9个问题,而不是10个或更多。 (正则表达式会忽略10,20,100 ......问题)