linux - 如何忽略包含 '+' 的字符串

标签 linux unix grep

问题可能是我忽略了多个字符串,但这就是我目前正在做的事情:

grep -Ev 'lost+found|controller|config'

所有带有“controller”和“config”的行都将被忽略,但所有带有“lost+found”的行仍然出现。是否有解决方法可以忽略包含“+”符号的字符串?

最佳答案

处理lost+found|controller|config:

lost+foundlostttt 中出现 1 次或多次 t 匹配。

正如 @zwer 和 @Barmar 提到的,+ 表示重复。

实际上,匹配的是:

enter image description here

+ 更改为 \+ (转义特殊字符)现在符合您的需要:

enter image description here

Regex101是探索正则表达式功能的绝佳资源:

enter image description here

关于linux - 如何忽略包含 '+' 的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45069688/

相关文章:

linux - 在 shell 中组合命令有效,但在运行 .sh 文件时无效

linux - 使用 linux 从文件中加入行

linux - EC2 - 未找到 Codedeploy NPM 错误

android - 在构建 cordova 项目时出现 ANDROID_HOME PATH 错误

启动 hbase 时未找到 JAVA_HOME。有什么建议么?

Linux 逻辑卷管理器

django - Gunicorn Socket 文件丢失

command-line - 使用 Silver Searcher 搜索文件和文件名

git - 如何 git grep 主存储库及其所有子模块?

linux - Ubuntu Cronjob 与 rsync