Linux命令在文件中查找特定行并在其下添加新行

时间:2014-03-24 17:33:54

标签: linux command

我正在尝试构建一个Linux命令来查找文件中的行并在该行下面添加更多行。例如,在文件中搜索"Application",然后获取该单词所在的行,并在其下方再添加三行。 我目前正在使用"sed -i '51icolumn1, column2, column3' test.txt"中的绝对行号,但如果此文件中有更改,我可能会将文本添加到错误的位置。

1 个答案:

答案 0 :(得分:2)

sed -i '/Application/a column1, column2, column3\ncolumn1, column2, column3' test.txt

解决您的问题?