【发布时间】:2021-04-09 02:13:52
【问题描述】:
我正在尝试使用 sed 删除列表(.txt 文件)中的单词,但它无法正常工作。 输出文件删除了它应该删除的单词以及它不应该删除的部分单词。
这是我尝试过的代码:
sed -E 's/('"$(tr '\n' '|' < listOfWords.txt )"')//gI' file.txt > output.txt
输入示例:
I would love to try or hear the sample audio your app can produce. I do not want to purchase, because I've purchased so many apps that say they do something and do not deliver.
Can you please add audio samples with text you've converted? I'd love to see the end results.
Thanks!
预期输出:
would love try hear sample audio app can produce. do want purchase, because ve purchased many apps say do something do deliver.
Can please add audio samples text ve converted? d love see end results.
单词列表示例:
...
I
to
or
the
your
not
so
that
they
and
you
with
Thanks
...
【问题讨论】:
-
欢迎来到 SO,感谢您在问题中添加您的努力(继续努力)。请在您的问题中添加输入和预期输出示例,以便我们更好地理解它,谢谢。
-
听起来你想锚定你的正则表达式,所以它只匹配单词边界。这是 GNU sed,还是我们只需要坚持标准强制功能?
-
还需要一个样本
listOfWords.txt来重现实际输出(并根据所需输出测试建议的答案)。理想情况下,示例应符合minimal reproducible example 规范——这是尽可能短的,在不更改使用时证明问题。如果您只需要删除两个词来显示问题的代码,那么构建一个 2 词列表和围绕它的示例输入/输出有助于保持简洁。