修改行(c)

修改行(c)

Content #

修改(c)命令允许修改数据流中整行文本的内容。它跟插入和附加命令的工作机制一样,必须在sed命令中单独指定一行: $ sed ‘2c\ > This is a changed line of text. > ’ data6.txt This is line number 1. This is a changed line of text. This is the 3rd line. This is the 4th line. $ 在这个例子中,sed编辑器会修改第三行中的文本。也可以用文本模式来寻址: $ sed ‘/3rd line/c\ > This is a changed line of text. > ’ data6.txt This is line number 1. This is line number 2. This is a changed line of text. This is the 4th line. $ 文本模式修改命令会修改所匹配到的任意文本行: $ cat data8.txt I have 2 Infinity Stones I need 4 more Infinity Stones I have 6 Infinity Stones! I need 4 Infinity Stones I have 6 Infinity Stones… I want 1 more Infinity Stone $ $ sed ‘/have 6 Infinity Stones/c\ > Snap! This is changed line of text. > ’ data8.txt I have 2 Infinity Stones I need 4 more Infinity Stones Snap! This is changed line of text. I need 4 Infinity Stones Snap! This is changed line of text. I want 1 more Infinity Stone $ 可以在修改命令中使用地址区间,但结果未必如愿: $ cat data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ $ sed ‘2,3c\ > This is a changed line of text. > ’ data6.txt This is line number 1. This is a changed line of text. This is the 4th line. $ sed编辑器会用指定的一行文本替换数据流中的两行文本,而不是逐一修改。

From #

Linux命令行与shell脚本编程大全