我尝试做的事情:
问题,删除该行中包含“34”的所有结果行
[tom@centos7-home-dell ~]$ find /home/tom/tmp/test_grep -name "*.log" -type f | xargs grep -i ERROR
/home/tom/tmp/test_grep/file1.log:ERROR:12;34
/home/tom/tmp/test_grep/file1.log:ERROR:12
/home/tom/tmp/test_grep/file2.log:ERROR:67890
/home/tom/tmp/test_grep/file2.log:ERROR:12;34
/home/tom/tmp/test_grep/file2.log:ERROR:12
[tom@centos7-home-dell ~]$ find /home/tom/tmp/test_grep -name "*.log" -type f | xargs grep -i ERROR | grep -vH "34"
(Standardeingabe):/home/tom/tmp/test_grep/file1.log:ERROR:12
(Standardeingabe):/home/tom/tmp/test_grep/file2.log:ERROR:67890
(Standardeingabe):/home/tom/tmp/test_grep/file2.log:ERROR:12
我的解决方案显示了预期的结果,但我不确定它是否可以。因为我使用 xargs -0 命令。请看这里:
[thor@centos7-home-dell wildfly]$ find /home/thor/tmp/test_grep -name "*.log" -type f | xargs grep -i ERROR
/home/thor/tmp/test_grep/file1.log:ERROR:12;34
/home/thor/tmp/test_grep/file1.log:ERROR:12
/home/thor/tmp/test_grep/file2.log:ERROR:67890
/home/thor/tmp/test_grep/file2.log:ERROR:12;34
/home/thor/tmp/test_grep/file2.log:ERROR:12
[thor@centos7-home-dell wildfly]$ find /home/thor/tmp/test_grep -name "*.log" -type f | xargs grep -i ERROR | xargs -0 | grep -v 34
/home/thor/tmp/test_grep/file1.log:ERROR:12
/home/thor/tmp/test_grep/file2.log:ERROR:67890
/home/thor/tmp/test_grep/file2.log:ERROR:12
我想你想做的就是这个:
find /home/tom/tmp/test_grep -name "*.log" -type f exec \
awk -v OFS=':' 'toupper($0) ~ /ERROR/ && !/34/ { print FILENAME, $0 }' {} +