Reputation: 6958
I've got a program that sends text to stdout. But I only want to keep those lines where the fifth column isn't '*'. That is the asterisk char, not the regex expression that catches everything. I can't seem to use escape for this, I've tried
./a.out |awk '$5!=* {print}'
awk: $5!=* {print}
awk: ^ syntax error
./a.out |awk '$5!=\* {print}'
awk: $5!=\* {print}
awk: ^ backslash not last character on line
Awk is of course not a requirement, but I thought this would be the simplest.
Thanks
Upvotes: 0
Views: 198
Reputation: 7526
In Perl:
perl -ane 'print unless $F[4] eq q(*)' file
The -n
switch wraps this loop aaround your script to read the filename argument(s) on the command line:
LINE:
while (<>) {
... # your script here
}
The -a
arms an autosplit of the line (on whitespace) into a predeclared array called @F. Unlike
awk` $F[0] is the first field only.
The -e
argument is simply your script.
Upvotes: 1
Reputation: 61449
awk
is similar to most Algol/C-family languages; literal strings require string quotes.
awk '$5 != "*" {print}'
Upvotes: 4