我需要通过服务器的访问日志查找不包含数字但12345包含单词的行。omgspecialword
什么是允许我为这些行 grep 的正则表达式?
如果数字和单词是固定的,则不需要正则表达式,只需用于|通过 2 个不同grep的管道和过滤结果
cat file_name | grep -v 12345 | grep omgspecialword
解释:
cat file_name |-cat打印内容file_name并将其传送到下一段
grep -v 12345 |排除包含匹配模式的行12345,然后将结果通过管道传递到下一段
grep omgspecialword过滤包含匹配模式的行omgspecialword。由于这里没有通过管道传输到其他任何内容,因此将其打印到标准输出。
grep 'omgspecialword' your_file|grep -v 12345
或者
awk '$0!~/12345/ && /omgspecialword/' your_file
或者
perl -lne 'if(/omgspecialword/ && !(/12345/)){print}' your_file