if you want to grep anything except foo, use grep -v or negative lookahead echo -e ‘foo\nbar\nboz’|grep -P ‘^(?!.*foo).*$’ bar boz it is just so beautiful ! e.g. get IP address except localhost in /etc/hosts grep -Po ‘^(?!127.0.0.1)[0-9.]+’ /etc/hosts 192.168.1.1 192.168.1.2 if you have no grep -P, use perl
negative regexp
- Post author By Laurent Schneider
- Post date
- Categories In Uncategorized