【发布时间】:2014-02-18 15:53:42
【问题描述】:
我想知道我是否可以删除\n(换行符),前提是当前行有一个或多个来自列表的关键字;例如,如果 \n 包含单词 hello 或 world,我想删除它。
示例:
this is an original
file with lines
containing words like hello
and world
this is the end of the file
结果是:
this is an original
file with lines
containing words like hello and world this is the end of the file
我想使用 sed 或 awk,如果需要,还可以使用 grep、wc 或任何可用于此目的的命令。我希望能够对很多文件执行此操作。
【问题讨论】:
-
您希望所需的输出替换文件的内容吗?
-
是的,我想进行所有更改,以便只有那些包含关键字的行删除它们的 \n 并保存文件
-
如果最后一行包含关键字,是否应该包含换行符?
-
应该只匹配整个单词吗?例如,
worlds是否应该被视为关键字word的匹配项? -
@potong 在我的情况下没关系,无论哪个更容易,如果添加换行符太麻烦,那么没关系
标签: regex linux sed awk newline