简体   繁体   English

grep 特定的正则表达式

[英]greping a specific regex

I am trying to print out every string that starts with three 0's, ends with three 1's and has zero or more 0's in between.我试图打印出以三个 0 开头、以三个 1 结尾并且中间有零个或多个 0 的每个字符串。

I was given a file with one large string, with XXX separating the different string I needed to check.我得到了一个包含一个大字符串的文件,用 XXX 分隔我需要检查的不同字符串。

I used sed to break up the string into separate lines wherever there is XXX, but I am trying pipe it into a grep with a specific regular expressions to display only the patterns that I want.我使用 sed 将字符串分解为单独的行,只要有 XXX,但我正在尝试将其通过管道传输到具有特定正则表达式的 grep 中,以仅显示我想要的模式。

sed "blah blah" | grep 000*111

This displays strings like "1", "111", "000".这将显示诸如“1”、“111”、“000”之类的字符串。 What wold the regex be to get this specific pattern?正则表达式是什么来获得这个特定的模式? Or can I not use grep with a regex like this?或者我不能在这样的正则表达式中使用 grep 吗?

Try this :尝试这个 :

sed "blah blah" | fgrep '000*111'

$ whatis fgrep

fgrep (1) - print lines matching a pattern fgrep (1) - 打印匹配模式的行

aka literal, not regex又名文字,而不是正则表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM