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
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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序列比对