4 ms·
The most portable way to do it with minimal overhead is with sed: sed -e '/pattern1/!d' -e '/pattern2/!d' which generalizes to more terms. Easier to rememb
by ykonstant 2y ago
The most portable way to do it with minimal overhead is with sed:
sed -e '/pattern1/!d' -e '/pattern2/!d'
which generalizes to more terms. Easier to remember and just as portable is
awk '/pattern1/ && /pattern2/'
but now you need to launch a full awk.
For more ways see https://unix.stackexchange.com/questions/55359/how-to-run-grep-with-multiple-and-patterns https://unix.stackexchange.com/questions/55359/how-to-run-gr...
- jrpelkonen 2y agoThese are good suggestions, but maybe it’s worth noting that one of the solutions offered in the article is not equivalent: tail -f /some/log/file | grep -E 'thing1.*thing2' This will only match if the subpatterns, i.e. thing1 & thing2, are in this order, and also require that the patterns do not overlap.