小编Fak*_*san的帖子

sed 替换不以 # 开头的匹配行

我有一个名为“test-file”的文件。它只有以下两行(第一行带有# 符号,第二行内容相同但没有散列):

#contents of line
contents of line
Run Code Online (Sandbox Code Playgroud)

我想使用 sed 命令更新/替换第二行的内容。我知道它的简单语法,例如:

sed -i 's/.*contents of line.*/updated contents/' test-file
Run Code Online (Sandbox Code Playgroud)

但是上面的命令正在替换这两行,而我不想在前面用 # 符号更新第一行。

sed text-processing

2
推荐指数
2
解决办法
3944
查看次数

标签 统计

sed ×1

text-processing ×1