一、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
原文地址:https://blog.csdn.net/ichen820/article/details/129525304

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2021-12-17
  • 2021-08-14
  • 2022-12-23
  • 2021-09-08
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案