I am trying to combine find and grep in a way to find folder names that start with k0 and search a specific file "test.log" for a word ERROR.
Something like:
find . -type d -name "k0*" -print | xargs grep ERROR test.log
unfortunately this command doesnt work as intended.
try this, I am assuming you have multiple files named test.log
in the folders whose names start with k0
here:
for file in $(find ./k0* -name 'test.log'); do
grep -w 'ERROR' $file
done
You can make this into a one-liner command like this:
for file in $(find ./k0* -name 'test.log'); do grep -w 'ERROR' $file; done
It's executable on terminal if you just post it.
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.