Skip to content

grep tricks

Exclude value from file

grep -f -v exclude.txt full.txt > result.txt

IP address regex

grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

Domain from emails

cat 1.txt 
Hello [email protected]    line1 value
Buy [email protected] line 2 stringX

grep -o '@[^ ]*' 1.txt | tr -d @
ddd.com
ftwr22.net

Any symbols in line before space

grep -o 'ansible_password=[^ ]*' hosts