一、shell上下两行
1.file
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
2.sed
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
二、sed多行
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
# 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
使用“制表符”\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
到此这篇关于shell通过sed上下两行合并成一行的实现的文章就介绍到这了,更多相关shell sed合并内容请搜索aitechtogether.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持aitechtogether.com!