I have a folder containing 100 sub-directories.
dir1 dir2 dir3 dir4...
Each sub-directory contains a file simv.log
Also, each directory either contains - FAILED.txt
or PASSED.txt
file.
I want to grep a pattern "ABCD" in the simv.log
files where FAILED.txt
is present.
I can find all directories containing FAILED.txt by using: find. -name "FAILED.txt" -print "%h\n"
find. -name "FAILED.txt" -print "%h\n"
How can I further use this output to grep ABCD in simv.log
file of those directories?
find . -name "FAILED.txt" -printf "%h/simv.log\0" | xargs -0 grep -F ABCD
should do the trick
find . -name "FAILED.txt" -printf "%h/simv.log\n" | while read line ; do grep ABCD -nr $line ; done;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.