This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
模式
[^echo]
匹配除e
、c
、h
和o< 之外的任何字符/代码>。例如,输入行“echo utility 123124135”包含所有这些字符,但它还包含不
e
、的字符c
、h
也不是o
。所以它确实匹配该模式。所有其他行也是如此,因为它们都包含除这些之外的字符。如果您将输入行“echohce”添加到数据文件中,您应该注意,当您使用模式运行 grep 时,它会被省略,因为它不包含任何其他字符。
如果您希望 grep 输出所有不包含文本“echo”的行,请尝试
grep -v echo test
。-v
开关告诉 grep 反转匹配的含义:输出与模式不匹配的行。并且模式“echo”将匹配包含文本“echo”的任何行。如果您尝试输出所有以“echo”开头的行,请尝试
grep ^echo test
。The pattern
[^echo]
matches any character excepte
,c
,h
, ando
. The input line "echo utility 123124135" for example contains all of these characters, but it also contains characters that are note
,c
,h
, noro
. So it does match the pattern. So do all of the other lines, because they all contain characters other than these.If you add an input line "echohce" to your data file, you should note that it is omitted when you run grep with your pattern, because it does not contain any other characters.
If you want grep to output all of the lines that don't contain the text "echo" then try
grep -v echo test
. The-v
switch tells grep to invert the sense of the match: output lines that don't match the pattern. And the pattern "echo" will match any line that contains the text "echo".If you are trying to output all of the lines that start with "echo" then try
grep ^echo test
.你可以这样做:
这将在屏幕上打印带有“echo”一词的行
you can do it this way:
That will print the line with the word "echo" on the screen
如果您尝试在行的开头匹配
echo
,请尝试但是,如果您尝试匹配所有不包含
echo
的行,请尝试编辑:哎呀,我刚刚意识到这是 @cdhowie 答案的精简版!
If you are trying to match
echo
at the beginning of a line, tryHowever, if you are trying to match all lines that do not contain
echo
then tryEDIT: oops, I've just realised that this is a cut-down version of @cdhowie's answer!
如果您想打印不包含单词“echo”的行,请尝试
If you want to print the lines that do not contain the word 'echo', try