怎么用shell改文件特定行的内容

一个文本文件,里面有如下内容
system:aaa
property:
length: 16
network:
property:
length: 32

这些行会在文件中出现很多次。我想把system:property:length 统一改成128,
其他的,比如network的都不要变,这个怎么用shell改?

第1个回答  2015-04-16

file3是文本文件

sed ' /system/ {
N
N
s/[1-9][1-9]*/128/
}' file3

追问

那两个‘N'是什么意思啊?这个length是system:property的一个属性,有的system中间可能会有其他属性,怎么办?比如
system:aaa
property:
duration:100
length: 16

我只想改所有system:property:length属性的值。

追答

有点没有看明白:必须 system property length 在连续的三行上么?

还是 system开始的行,后面几行中的一个 length都可以修改

另外,system后是否肯定存在length 行

本回答被提问者和网友采纳
相似回答