学习总记录两个我觉得有意思的命令cat新建简单文件,sed任意特定行插入。

cat 一般用来查看里面的文件内容。

今天我想说的是

[root@instance-erv5z0qp tmp]# cat > testfile << "over"
> This is my test
> hello ,my english very pool
> bye bye
> over
[root@instance-erv5z0qp tmp]# cat testfile
This is my test
hello ,my english very pool
bye bye

后面的单词是结束语句提示词,这样新建一个简单的编辑好的文件感觉非常方便,不需要用vim新建保存什么的。

还有一个sed,sed可以配合正则对一些输出进行删除,替换,

我主要说的是插入

[root@instance-erv5z0qp tmp]# cat testfile
This is my test
hello ,my english very pool
bye bye
[root@instance-erv5z0qp tmp]# sed -i '$a This is insert last' testfile
[root@instance-erv5z0qp tmp]# cat testfile
This is my test
hello ,my english very pool
bye bye
This is insert last
[root@instance-erv5z0qp tmp]# sed -i '2a second insert test' testfile
[root@instance-erv5z0qp tmp]# cat testfile
This is my test
hello ,my english very pool
second insert test
bye bye
This is insert last
通过sed可以非常方便的在任意一行插入字段,第一个红色标注的$a表示最后插入

第二个红色标注2a为第二行后面插入,a为插入的参数。

原文地址:https://www.cnblogs.com/sidianok/p/11692938.html