[英]Output in grep command
I'm new with regexp and I believe this is a beginner's glitch in getting the output. 我是regexp的新手,我相信这是初学者在获取输出时的故障。
My regexp for AB(CD) digits/digits is: [AZ]+[^a-zA-Z0-9][AZ]+[^a-zA-Z0-9] [0-9]+[^a-zA-Z0-9][0-9]+
我的AB(CD)数字/数字的正则表达式是:
[AZ]+[^a-zA-Z0-9][AZ]+[^a-zA-Z0-9] [0-9]+[^a-zA-Z0-9][0-9]+
Grep command is: grep "regexp" xyz.txt
Grep命令是:
grep "regexp" xyz.txt
there's no output to above command, but when I use sublime editor for same regex, i gets the desired result. 上面的命令没有输出,但是当我对相同的正则表达式使用sublime编辑器时,我得到了想要的结果。 Tried many attempts with grep command , the only time it gave results is when I deleted the
[0-9]+[^a-zA-Z0-9][0-9]+
portion from regex because there is a space in between but still the results were not desired. 使用grep命令进行了多次尝试,它给出的唯一结果是当我从正则表达式中删除
[0-9]+[^a-zA-Z0-9][0-9]+
部分时,因为之间存在空格但结果仍然不理想。 Tried grep -e
and grep --regexp=
too, no results. 也尝试了
grep -e
和grep --regexp=
,没有结果。
Can someone tell me where I went wrong or the correct syntax for this command. 有人可以告诉我我哪里出了问题或该命令的正确语法。 Much grateful.
非常感谢。
Edit: 编辑:
The data looks like the following: 数据如下所示:
AB(CD) nnnnn/nnnnnn AB(CD) nnnnnn/nnnnn AB(CD) nnnnn/nnnnnn AB(CD) nnnnn/nnnnnn AAB(CD) nnnnn/nnnnnn .... .... further P & C
I was looking only for AB(CD) nnnn/nnnnnn. 我只在寻找AB(CD)nnnn / nnnnnn。 Would really like to learn the correct expression.
真的很想学习正确的表达方式。
使用grep -E,因为它将grep切换到特殊模式,以便将该表达式评估为ERE(扩展正则表达式),而不是其常规模式匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.