[英]Printing lines from a file where a specific field does not start with something
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:#hdfghdfg
A:B: #dfdfdfg A:B:#dfdfdfg
A:B:C A:B:C
Desired output: 所需的输出:
A:B:C A:B:C
I tried: 我试过了:
awk -F : '$3 ~ /^#/ { print }' run_out5 > run_out6 awk -F:'$ 3〜/ ^#/ {print}'run_out5> run_out6
but it is not working 但它不起作用
Thanks, 谢谢,
Jagrati 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}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.