1

I am searching all *.out files from a specific directory and trying to list all the file names where the given string is not present in those files or not matching by executing the below-listed command.

find . -type f -name "*.out" -exec grep -L "226 Transfer complete." {} \;

Unfortunately, it is not listing the files which do not have the string 226 Transfer complete, instead it displayed the series of string 226 Transfer complete.

@don_crissti, as per your solution

find . -type f ! -exec grep -q 'PATTERN' {} \; -print 

the 'PATTERN' present twice anywhere in my test files. If one of the locations having the 'PATTERN' and other does not have, then it is not listing the file (In my case, it should list). can I use count to validate it? Like if I get the count less than 2, then it should list the files which are considered to be erroneous.

16
  • 3
    Not really sure, but try -v option in grep instead of -L.
    – Thomas
    Jan 23, 2017 at 18:14
  • Are you sure the string "226 Transfer complete." is correct? Is there really supposed to be a . (period) there? And remember . match one character of anything in grep - while \. matches an actual .... Do you need it all? Wouldn't the numeric-code be enough? Eg. "^226 Transf" - beginning of line starts with 226 Transf - may be enough... or maybe "^226 Trans.*comp"... Also try [Tt] and [Cc] to match both upper-and lower-case. Jan 23, 2017 at 18:20
  • @BaardKopperud I was thinking that too, but it doesn't explain why he got that string on the terminal, unless he's using a grep that doesn't understand -L...
    – Kusalananda
    Jan 23, 2017 at 18:21
  • What system are you on and does grep --version output anything?
    – Kusalananda
    Jan 23, 2017 at 18:22
  • I mean as @Thomas wrote, the alternative is using -v -- perhaps combined with -l... -l prints names of files with at least one match, -v reverse the pattern... but together - looking at the description of the man-page - that should be exactly what -L (which you're already using!) should do. Jan 23, 2017 at 18:27

0

Browse other questions tagged .