1、删除文档的第一行 sed -i '1d' 2、删除文档的最后一行 sed -i '$d' 3、在文档指定行中增加一行 例如文档如下: echo "1"; echo "2"; echo "4"; echo "5"; 想要在 echo "2"; 后面加上一条 echo "3"; 可以用如下命令 sed -i '/echo "2";/aecho "3";' 之所以用分号,是因为文本中本来就有。也就是说分号不是必须的! 抽象出来就是: sed -i '/* /a*' 4、删除文件中的一行 sed -i '3d' 5、删除文件中包含某个关键字开头的所有行 sed -i '/^QWQ/d' 6、删除文件中包含某个关键字的所有行 sed -i '/QWQ/d'
Linux使用sed命令对进行文件行操作
AI-generated summary
This article explains how to use the sed command in Linux to perform various operations on file lines, including deleting the first or last line, adding a line after a specified line, deleting a specific line, and deleting all lines containing a certain keyword. Examples and commands are provided.