由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - regular expression question
相关主题
Regular expression的问题[转载] Help with Perl Regular Expression
a question about regular expressionregular expessions in vi
paste command 里面的 -请教一个sed命令
[转载] 一个简单的regular expression问题再次急问: *.tgz 文件怎么解?
[转载] Re: 一个简单的regular expression问题双面打印
regular expression中回车用什么表示?help on job control commands
Regular expressionwait on line: simple question
Regular ExpressionsHow to use the command history in SUN?
相关话题的讨论汇总
话题: 4096话题: 2048话题: a423话题: b406话题: 8192
进入Unix版参与讨论
1 (共1页)
s*****i
发帖数: 650
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
a******g
发帖数: 88
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

s*****i
发帖数: 650
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

a******g
发帖数: 88
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

s**a
发帖数: 79
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 ^

1 (共1页)
进入Unix版参与讨论
相关主题
How to use the command history in SUN?[转载] Re: 一个简单的regular expression问题
regex: what does [^ ] mean?regular expression中回车用什么表示?
[转载] perl: regexRegular expression
如何删除从行首到某个特定字符串之间的内容?Regular Expressions
Regular expression的问题[转载] Help with Perl Regular Expression
a question about regular expressionregular expessions in vi
paste command 里面的 -请教一个sed命令
[转载] 一个简单的regular expression问题再次急问: *.tgz 文件怎么解?
相关话题的讨论汇总
话题: 4096话题: 2048话题: a423话题: b406话题: 8192