0

This question already has an answer here:

I am running the same job on around 1000 input files. Around 10% of these will fail, but the only way of checking this is to scroll through the output files and check if it states completed without error. To save time is there a way of using the grep command to

  • Search in a directory specifically through output files only (named oxxxxx),
  • for those that do not contain the phrase completed without error,
  • listing these oxxxx files in the terminal window.

Thank you!

marked as duplicate by Jeff Schaller, αғsнιη, Rui F Ribeiro, Jesse_b, G-Man Apr 14 '18 at 19:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Using GNU grep's -L extension:

grep -L 'completed without error' o*

-L, --files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

Without GNU grep:

for f in o*; do grep -q "completed without error" "$f" || printf "%s\n" "$f"; done
  • The "without GNU" example should also include o* as the target files for OP's case – cunninghamp3 Apr 14 '18 at 12:15
1
grep -R <pattern> -L *

-R      recursively search
-L      files without match    

Example:

 touch $(seq 1 100)  # create 100 files
 echo "testing" > 28
 echo "testing" > 32
 echo "testing" > 10
 echo "testing" > 15
 echo "testing" > 95
 echo "testing" > 72
 echo "testing" > 34
 echo "testing" > 25 # eight files with pattern
 $ grep -l test *|wc -l  # files that contains pattern
   8
 $ grep -L test *|wc -l  # files that doesn't contain pattern
  92

Not the answer you're looking for? Browse other questions tagged or ask your own question.