UNIX grep 命令

发布于 2024-11-28 17:18:58 字数 1549 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雾里花 2024-12-05 17:18:58

模式 [^echo] 匹配除 echo< 之外的任何字符/代码>。例如,输入行“echo utility 123124135”包含所有这些字符,但它包含 e的字符ch 也不是 o。所以它确实匹配该模式。所有其他行也是如此,因为它们都包含除这些之外的字符。

如果您将输入行“echohce”添加到数据文件中,您应该注意,当您使用模式运行 grep 时,它会被省略,因为它包含任何其他字符。

如果您希望 grep 输出所有不包含文本“echo”的行,请尝试 grep -v echo test-v 开关告诉 grep 反转匹配的含义:输出与模式不匹配的行。并且模式“echo”将匹配包含文本“echo”的任何行。

如果您尝试输出所有以“echo”开头的行,请尝试 grep ^echo test

The pattern [^echo] matches any character except e, c, h, and o. The input line "echo utility 123124135" for example contains all of these characters, but it also contains characters that are not e, c, h, nor o. 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.

始于初秋 2024-12-05 17:18:58

你可以这样做:

cat text | grep echo 

这将在屏幕上打印带有“echo”一词的行

you can do it this way:

cat text | grep echo 

That will print the line with the word "echo" on the screen

鸠书 2024-12-05 17:18:58

如果您尝试在行的开头匹配 echo ,请尝试

grep "^echo" test

但是,如果您尝试匹配所有不包含 echo 的行,请尝试

grep -v "echo" test

编辑:哎呀,我刚刚意识到这是 @cdhowie 答案的精简版!

If you are trying to match echo at the beginning of a line, try

grep "^echo" test

However, if you are trying to match all lines that do not contain echo then try

grep -v "echo" test

EDIT: oops, I've just realised that this is a cut-down version of @cdhowie's answer!

勿忘心安 2024-12-05 17:18:58

如果您想打印不包含单词“echo”的行,请尝试

grep -v "echo" test

If you want to print the lines that do not contain the word 'echo', try

grep -v "echo" test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文