Created
July 22, 2015 01:47
-
-
Save blindpet/00012f15d870a60f9e6a to your computer and use it in GitHub Desktop.
bash match one word but exclude another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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