Skip to content

Instantly share code, notes, and snippets.

@blindpet
Created July 22, 2015 01:47
Show Gist options
  • Save blindpet/00012f15d870a60f9e6a to your computer and use it in GitHub Desktop.
Save blindpet/00012f15d870a60f9e6a to your computer and use it in GitHub Desktop.
bash match one word but exclude another
use double grep
command | grep 'what you want' | grep -v 'whatyoudontwant'
Or use awk
awk '/XXX/ && !/YYY/' file
^^^^^ ^^^^^^
I want it I don't want it
You can even say something more complex. For example: I want those lines containing either XXX or YYY, but not ZZZ:
awk '(/XXX/ || /YYY/) && !/ZZZ/' file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment