Remix.run Logo
radarsat1 8 hours ago

Side note maybe, but is there an alternative to chaining two greps?

ykonstant 7 hours ago | parent [-]

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-gr...

jrpelkonen 3 hours ago | parent [-]

These 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.