查找具有正则表达式匹配和不同正则表达式不匹配的文件
Find files with regex match and different regex not match
我有三个文件 foo1.txt
、foo2.txt
和 foo3.txt
,其中包含以下行
# foo1.txt
JOBDONE
和
# foo2.txt
Execution halted
和
# foo3.txt
Execution halted
JOBDONE
我已经找到了同时具有 JOBDONE
和 Execution halted
的那些:
find ./foo*.txt | xargs grep -l 'Execution halted' | xargs grep -l "JOBDONE"
但无法找到那些具有 JOBDONE
或 Execution halted
而不是两者的文件。我试过:
find ./foo*.txt | xargs grep -lv "JOBDONE" | xargs grep -l "Execution halted"
find ./foo*.txt -exec grep -lv "JOBDONE" {} \; | xargs grep -l "Execution halted"
但(据我所知)错误地返回
./foo2.txt
./foo3.txt
我对 xargs
和 exec
如何与 grep 一起工作的理解有什么问题,以及我如何使用 grep 或其他可移植命令来 select 那些具有 [=19] 的日志=] 但不是 Execution halted
反之亦然?
这是一个gnu awk
(由于RS中有多个字符的gnu)
awk -v RS="#-#-#" '/JOBDONE/ && /Execution halted/ {print FILENAME}' foo*
foo3.txt
将 RS
设置为文件中没有的内容,它将所有行作为一个线程。
然后测试长行是否有两个string,如果有则打印filename
我有三个文件 foo1.txt
、foo2.txt
和 foo3.txt
,其中包含以下行
# foo1.txt
JOBDONE
和
# foo2.txt
Execution halted
和
# foo3.txt
Execution halted
JOBDONE
我已经找到了同时具有 JOBDONE
和 Execution halted
的那些:
find ./foo*.txt | xargs grep -l 'Execution halted' | xargs grep -l "JOBDONE"
但无法找到那些具有 JOBDONE
或 Execution halted
而不是两者的文件。我试过:
find ./foo*.txt | xargs grep -lv "JOBDONE" | xargs grep -l "Execution halted"
find ./foo*.txt -exec grep -lv "JOBDONE" {} \; | xargs grep -l "Execution halted"
但(据我所知)错误地返回
./foo2.txt
./foo3.txt
我对 xargs
和 exec
如何与 grep 一起工作的理解有什么问题,以及我如何使用 grep 或其他可移植命令来 select 那些具有 [=19] 的日志=] 但不是 Execution halted
反之亦然?
这是一个gnu awk
(由于RS中有多个字符的gnu)
awk -v RS="#-#-#" '/JOBDONE/ && /Execution halted/ {print FILENAME}' foo*
foo3.txt
将 RS
设置为文件中没有的内容,它将所有行作为一个线程。
然后测试长行是否有两个string,如果有则打印filename