linux 中实现按照行交叉合并两个文件

 

001、方法1

[root@pc1 test01]# ls
a.txt  b.txt
[root@pc1 test01]# cat a.txt
1 2
3 4
5 6
[root@pc1 test01]# cat b.txt
a b
c d
e f
[root@pc1 test01]# paste -d "_" a.txt b.txt
1 2_a b
3 4_c d
5 6_e f
[root@pc1 test01]# paste -d "_" a.txt b.txt | tr "_" "\n"
1 2
a b
3 4
c d
5 6
e f

 

002、方法2

[root@pc1 test01]# ls
a.txt  b.txt
[root@pc1 test01]# cat a.txt
1 2
3 4
5 6
[root@pc1 test01]# cat b.txt
a b
c d
e f
[root@pc1 test01]# paste -d "\n" a.txt b.txt  ## 直接使用换行符作为合并后的分割符
1 2
a b
3 4
c d
5 6
e f

 

原文:https://www.cnblogs.com/chenwenyan/p/9634463.html

 

posted @ 2023-09-13 18:04  小鲨鱼2018  阅读(194)  评论(0编辑  收藏  举报