I have some files that contain a particular strings. What I want to do is, search a location for the file; if the file exists grep for the pattern; if true, do something.
find -iname file.xxx| xargs -I {} if grep -Fq "string" {} ; then echo {} ; fi
The problems are:
xargsis not working with the if statement.echo {}does not give the file name, instead gives{}.
How do I fix these?
Try to run the command through a shell like this:
where the original command has been surrounded by quotes and
bash -c.