avatar
regular expression question# Unix - 噫吁兮,危乎高哉
s*i
1
source file input.txt:
386 2048 D403 MG0011 100
486 4096 D404 MG0012 270
386 8192 A423 CC0177 400
486 8192 A424 CC0182 670
286 4096 A423 CC0183 100
286 4096 A425 CC0184 80
68020 2048 B406 EE1029 80
68030 2048 B410 EE1030 100
"trs80" 64 Z101 EL0020 0
If I use the following command:
$> awk '$1 ~ /[^23468]/ {print $0}' input.txt
The output is:
XT 640 D402 MG0010 0
Mac 4096 B407 EE1027 80
Apple 4096 B406 EE1028 40
68020 2048 B406 EE1029 80
68030 2048 B410 EE1030 100
$unix
avatar
a*g
2
?? when I run your command I got
>awk '$1 ~ /[^23468]/ {print $0}' input.txt
68020 2048 B406 EE1029 80
68030 2048 B410 EE1030 100
"trs80" 64 Z101 EL0020 0

【在 s*****i 的大作中提到】
: source file input.txt:
: 386 2048 D403 MG0011 100
: 486 4096 D404 MG0012 270
: 386 8192 A423 CC0177 400
: 486 8192 A424 CC0182 670
: 286 4096 A423 CC0183 100
: 286 4096 A425 CC0184 80
: 68020 2048 B406 EE1029 80
: 68030 2048 B410 EE1030 100
: "trs80" 64 Z101 EL0020 0

avatar
s*i
3
I am sorry for there is sth wrong with the pasting.
the input file should be like below:
XT 640 D402 MG0010 0
386 2048 D403 MG0011 100
486 4096 D404 MG0012 270
386 8192 A423 CC0177 400
486 8192 A424 CC0182 670
286 4096 A423 CC0183 100
286 4096 A425 CC0184

【在 a******g 的大作中提到】
: ?? when I run your command I got
: >awk '$1 ~ /[^23468]/ {print $0}' input.txt
: 68020 2048 B406 EE1029 80
: 68030 2048 B410 EE1030 100
: "trs80" 64 Z101 EL0020 0

avatar
a*g
4
Your original regex means that there is a match when anything other than
2,3,4,6, or 8 appears in $1. What you what to say, is that if anything
like 2,3,4,6,or 8 appears, it does not match.
Use this
awk '$1 !~ /[23468]/' input.txt
notice the ! before ~, and the removal of ^

【在 s*****i 的大作中提到】
: I am sorry for there is sth wrong with the pasting.
: the input file should be like below:
: XT 640 D402 MG0010 0
: 386 2048 D403 MG0011 100
: 486 4096 D404 MG0012 270
: 386 8192 A423 CC0177 400
: 486 8192 A424 CC0182 670
: 286 4096 A423 CC0183 100
: 286 4096 A425 CC0184

avatar
s*a
5
Isn't that just
awk '/^[^23468]/' input.txt?
cheers,
sd

【在 a******g 的大作中提到】
: Your original regex means that there is a match when anything other than
: 2,3,4,6, or 8 appears in $1. What you what to say, is that if anything
: like 2,3,4,6,or 8 appears, it does not match.
: Use this
: awk '$1 !~ /[23468]/' input.txt
: notice the ! before ~, and the removal of ^

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。