目录一、shell上下两行1.file2.sed二、sed多行
cat file.txt
host1
192.168.0.1
host2
192.168.0.2
host3
192.168.0.3
host4
192.168.0.4
host5
192.168.0.5
192.168.0.1
host2
192.168.0.2
host3
192.168.0.3
host4
192.168.0.4
host5
192.168.0.5
sed ‘N;s/\n/ :/’ file
# cat file.txt | sed ‘N;s/\n/ :/’
host1 :192.168.0.1
host2 :192.168.0.2
host3 :192.168.0.3
host4 :192.168.0.4
host5 :192.168.0.5
host1 :192.168.0.1
host2 :192.168.0.2
host3 :192.168.0.3
host4 :192.168.0.4
host5 :192.168.0.5
N (next)多行操作命令,文本前后两行合并为一行
# cat file.txt
host11
192.168.0.1
host222
192.168.0.2
host3
192.168.0.3
host44
192.168.0.4
host555
192.168.0.5
host11
192.168.0.1
host222
192.168.0.2
host3
192.168.0.3
host44
192.168.0.4
host555
192.168.0.5
# sed ‘N;s/\n/ :/’ file.txt
host11 :192.168.0.1
host222 :192.168.0.2
host3 :192.168.0.3
host44 :192.168.0.4
host555 :192.168.0.5
host11 :192.168.0.1
host222 :192.168.0.2
host3 :192.168.0.3
host44 :192.168.0.4
host555 :192.168.0.5
使用“制表符”\t对齐边缘
# sed ‘N;s/\n/ \t/’ file.txt
host11 192.168.0.1
host222 192.168.0.2
host3 192.168.0.3
host44 192.168.0.4
host555 192.168.0.5
host11 192.168.0.1
host222 192.168.0.2
host3 192.168.0.3
host44 192.168.0.4
host555 192.168.0.5
到此这篇关于shell通过sed上下两行合并成一行的实现的文章就介绍到这了,更多相关shell sed合并内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:合并一个文件夹下多个文件内容的单行shell命令shell脚本语言的使用(超全超详细)shell脚本两个文件关键行合并方式
© 版权声明
文章版权归作者所有,未经允许请勿转载。