Preferences

Just posting this without trying it out...grep -nH gives you line numbers and full filepath context, and as another commenter said, -ve allows you to string multiple excludes, so grep -inH <search> -ve not_this -ve nor_this -ve nor_that.

You don’t have to stack -v like that: -v inverts all the -e expressions, so this should be equivalent:

    grep -inHv -e foo -e bar -e baz
So, awk sort of works as a fancy grep:

    ps axjw | awk '(/zsh/ || /login/) && !(/awk/ || /direnv/)'
And you can easily add features like "print the first line unconditionally:

    ps axjw | awk 'NR == 1 {print} (/zsh/ || /login/) && !(/awk/ || /direnv/)'
IMO, awk is in a pretty uniquely sweet spot between grep and perl/ruby/python.
Thanks for the grep tip!

Unfortunately I've not put in the effort to learn awk past printing the n-th column of ls (my typical use) - the extra syntax required to properly 'quote' and {} things puts me off.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal