Re:CLI: Improved
by vitorbaptistaa on Thursday August 30, 2018 @10:08PM
(#17882378)
I'm not in my computer now, but doesn't "grep -v" solves your issue? If I remember correctly, it inverts the query, so it would return 0 if there wasn't a match.
No, -v will return 0 unless every line matches:
$ cat > foo
here's
some
random
text
$ grep -v some foo; echo $?
here's
random
text
0
$ grep -v bar foo; echo $?
here's
some
random
text
0
$ grep -vE "(here's|some|random|text)" foo; echo $?
1How about "awk /pattern/"?
Re:CLI: Improved
by mangamadaiyan on Friday August 31, 2018 @03:07AM
(#17883530)
Would grep -c work for your use-case?
I know why the authors chose to use a non-zero return code as the default, but when I'm using grep deep in a pipeline and doing my own checking of the results to see if nothing was found, I don't need grep bombing out the whole pipeline with a non-zero return code.
The alternative of being forced to use "(grep pattern||true)" instead of a plain "grep -q" is kinda painful.