First question here, so go easy (:
I have a 385 files which are the result of simulations, named ###_result.dat. However, some of the results resulted in errors, which I can grep for using the -l flag since these files always contain the character “=”.
So getting the error-files is no problem:
grep -l = *_result.dat | wc -l 4
When I want to list the files without any errors, I thought I could just invert the grep using the v-flag:
grep -v -l = *_result.dat | wc -l 385 ls | wc -l 385
So this gives me all files, including the ones with errors.
What am I doing wrong here?
Now I know I could probably just throw out the bad ones and continue from there, but I’d like to know why this usage of grep doesn’t work for me.
Advertisement
Answer
You should use grep -L
. What you did here is find the files (-l
) containing lines that do not (-v
) match your pattern.