搜索连续不包含某些字符的行

搜索连续不包含某些字符的行

我有一篇新闻文章需要稍微编辑一下。基本上,我需要连续搜索两次或多次不包含字符 t 和 h 的所有行,并用这些行中的字符 D 替换 4 个字母的单词。不知道从哪里开始。例如,我有这样的文字

Animals are multicellular eukaryotic organisms which form a biological kingdom Animalia. 
Historically, Aristotle divided animals into those with blood and those without

我希望它看起来像

Animals are multicellular eukaryotic organisms which D a biological kingdom Animalia.
Historically, Aristotle divided animals into those with blood and those without

答案1

如果您的文件名为 Myfile.txt 您可以运行:

grep -Ev '[Tt][Tt]|[Hh][Hh]' Myfile.txt |  awk '{ gsub("([^[:alnum:]]|^)[[:alnum:]]{4}([[:space:]]|[[:punct:]])"," D ");print $0}' > MyEditedFile.txt

相关内容