sed命令

内容纲要

sed简介

手册:https://www.gnu.org/software/sed/manual/

实践

-i表示编辑文件,不加-i表示将结果输出到标准输出

插入数据到第n行

插入数据到第一行

sed -i '1izxmtest_first' zxm.test

插入数据到第二行

sed -i '2izxmtest_second' zxm.test

实际操作演示
使用-i参数,可见原始文件被编辑

root@b84cf0148842:/# echo "testLine1" > zxm.test
root@b84cf0148842:/# sed -i '1izxmtest_first' zxm.test
root@b84cf0148842:/# cat zxm.test
zxmtest_first
testLine1
root@b84cf0148842:/# sed -i '2izxmtest_second' zxm.test
root@b84cf0148842:/# cat zxm.test
zxmtest_first
zxmtest_second
testLine1

不使用-i参数,原始文件未被编辑

root@b84cf0148842:/# sed  '2izxmtest_third' zxm.test
zxmtest_first
zxmtest_third
zxmtest_second
testLine1
root@b84cf0148842:/# cat zxm.test
zxmtest_first
zxmtest_second
testLine1
sed命令

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

滚动到顶部