find . -type f -exec sh -c ' if [cat ${1} == "abc" ] then echo ${1} fi' _ {} \;
I got this error:
_: -c: line 1: syntax error: unexpected end of file
What I what to do here is :
find all files in this directory, print file name if file content is abc.
Thank you !
The problem here is that the
[(aka ‘test’) needs to be separated fromcatby a space, like so:You’re also missing semicolons after the
ifstatement and before thefistatement (it looks like you had these on separate lines originally, based on the spacing that was there, probably due to the way that you had it indented)As pointed out in the comment below, running this will give the error message
too many arguments in if []. Using double quotes around"cat ${1}"will avoid the error message, but this simply compares the expansion of"cat ${1}"with"abc". What you’re probably looking for is[ "$(cat ${1})" == "abc" ]. Unfortunately, this is likely to cause problems when you compare a very long file with"abc".You could use
grepto do the test, or take a checksum (e.g.shasum) of the file, and test that against the checksum of"abc", depending on what why you’re doing the test.