【发布时间】:2023-04-03 00:13:01
【问题描述】:
我想在 Linux 中使用 SED 命令从文本文件中删除所有包含一个字母的单词。比如我有文字:
yes said holmes answering the look rather than the words it is
so i know all about mccarthy
the old man sank his face in his hands god help me he cried but
i would not have let the young man come to harm i give you my word
that i would have spoken out if it went against him at the assizes
i am glad to hear you say so said holmes gravely
i would have spoken now had it not been for my dear girl it would
break her heartit will break her heart when she hears that i am
arrested
使用正则表达式,我使用 SED 命令如下:
sed -E 's/(\s[a-z]\s)/ /g' examplefile > destinationfile
我运行命令后,结果看起来和以前一样,没有任何变化。我错过了什么?
【问题讨论】:
-
好吧,你只删除了一个字母的单词,所以输出会类似,见ideone.com/tSMtdY。反正输出和输入是不一样的。
-
请将该示例输入的所需输出(无描述)添加到您的问题(无评论)。