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 outpu开发者_运维问答t:
A:B:C
I tried:
awk -F : '$3 ~ /^#/ { print }' run_out5 > run_out6
but it is not working
Thanks,
Jagrati
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 }'
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}'
精彩评论