views:

43

answers:

2

Hi,

I want to print all the lines where 3rd field (fields separated by : ) DO NOT start with # (to signify that 3rd field is a comment). Please note that there may be space(s) between : and #.

Example Input:

A:B:#hdfghdfg

A:B: #dfdfdfg

A:B:C

Desired output:

A:B:C

I tried:

awk -F : '$3 ~ /^#/ { print }' run_out5 > run_out6

but it is not working

Thanks,

Jagrati

+4  A: 

The regex could be a tiny bit cleaner:

awk -F: '$3 !~ /^ ?#/ { print }'

It's often better to expect repeated whitespace (space or tab) rather than a single space character, which can look identical in printed output.

awk -F: '$3 !~ /^[[:space:]]*#/ { print }'
Phil
A: 

Use !~ to select lines that do not match the regexp.
Adjust the regexp so that it will match fields with leading spaces.

awk -F : '$3 !~ /^ *#/ {print}'
Chris Johnsen