Maitre Bart
Maitre Bart

Reputation: 157

awk: is there a way to filter non-matching regex?

In certain cases I use awk this way:

% some_command | awk /regex/

since it does not buffer its output and I can get some_command's output right away. There's a way to do it with grep as well (using --line-buffered I think) but I don't have this version of grep on the system I work on. So awk does the job.

However some times I'd like to filter non-matching regex (i.e. like grep's -v option). Is there a way to do that with awk?

Upvotes: 1

Views: 372

Answers (1)

Wintermute
Wintermute

Reputation: 44063

Use

some_command | awk '!/regex/'

The ! means "not," so this selects lines that don't match regex.

Upvotes: 2

Related Questions