小编Luk*_*ali的帖子

如何使用 grep 搜索包含两个单词之一但不是两个单词的行?

我想在文本文件中搜索带有 'word1' XOR 'word2' 的行。所以它应该输出带有 word1、word2 的行,而不是带有这两个词的行。我想使用 XOR 但我不知道如何在 linux 命令行中编写它。

我试过:

grep 'word1\|word2' text.txt
grep word1 word2 text.txt
grep word1 text.txt | grep word2
grep 'word1\^word2' text.txt
Run Code Online (Sandbox Code Playgroud)

还有更多,但无法成功。

grep text-processing

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

grep ×1

text-processing ×1