Linux 中 sed命令在指定行前添加空行

 

001、

复制代码
[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
33 aa 44 aa 88
aa 33 aa ff kk
33 aa 88 22 mm
88 33 44 22 99
[root@PC1 test]# sed '2 s/.*/\n&/' a.txt   ## 在第二行前添加空行
33 aa 44 aa 88

aa 33 aa ff kk
33 aa 88 22 mm
88 33 44 22 99
复制代码

 

 

002、sed

复制代码
[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
33 aa 44 aa 88
aa 33 aa ff kk
33 aa 88 22 mm
88 33 44 22 99
[root@PC1 test]# sed 2g a.txt      ## 在第二行前添加空行
33 aa 44 aa 88

33 aa 88 22 mm
88 33 44 22 99
[root@PC1 test]# sed 2G a.txt      ## 在第二行后添加空行
33 aa 44 aa 88
aa 33 aa ff kk

33 aa 88 22 mm
88 33 44 22 99
复制代码

 。

 

003、

复制代码
[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
33 aa 44 aa 88
aa 33 aa ff kk
33 aa 88 22 mm
88 33 44 22 99
[root@PC1 test]# awk '{if(NR == 2){printf("\n"); print $0} else {print $0}}' a.txt
33 aa 44 aa 88

aa 33 aa ff kk
33 aa 88 22 mm
88 33 44 22 99
[root@PC1 test]# awk '{if(NR == 2){print $0; printf("\n")} else {print $0}}' a.txt
33 aa 44 aa 88
aa 33 aa ff kk

33 aa 88 22 mm
88 33 44 22 99
复制代码

 。

 

posted @   小鲨鱼2018  阅读(129)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-07-15 *** These critical programs are missing or too old: compiler
2023-07-15 *** These critical programs are missing or too old: make compiler
2023-07-15 lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/liujiaxin01/.aspera
2023-07-15 linux 中 md5sum -c选项
2023-07-15 linux 中gz文件解压的同时保留源文件
2023-07-15 blast软件比对库nr、nt库的下载、构建索引、序列比对
2023-07-15 linux 中blast序列比对
点击右上角即可分享
微信分享提示