monkeyking
monkeyking

Reputation: 6958

only print lines with specific column not *

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

Answers (4)

DDD
DDD

Reputation: 21

Try this:

awk '$5!="*"{print}'

Upvotes: 2

potong
potong

Reputation: 58488

This might work for you:

awk '$5 !~ /^[*]$/' file

Upvotes: -1

JRFerguson
JRFerguson

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. Unlikeawk` $F[0] is the first field only.

The -e argument is simply your script.

Upvotes: 1

geekosaur
geekosaur

Reputation: 61449

awk is similar to most Algol/C-family languages; literal strings require string quotes.

awk '$5 != "*" {print}'

Upvotes: 4

Related Questions