Linux命令学习:文本拼接 paste 和 join

小熊 Linux评论2,270字数 2112阅读7分2秒阅读模式

Linux命令学习:文本拼接 paste 和 join

paste 拼接

直接逐行遍历拼接起来。

$ cat uuid
459A978D-84D1-4822-BE61-394669D229C5
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D
90B4D95C-7F0C-4946-8C02-3A43367CC795
1FDA8320-57AB-4446-AC48-86C9AE22255B
D5F2D01A-9E32-4C9D-A795-07DC50425ACA

$ cat ip
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5

$ paste uuid ip
459A978D-84D1-4822-BE61-394669D229C5    192.168.1.1
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D    192.168.1.2
90B4D95C-7F0C-4946-8C02-3A43367CC795    192.168.1.3
1FDA8320-57AB-4446-AC48-86C9AE22255B    192.168.1.4
D5F2D01A-9E32-4C9D-A795-07DC50425ACA    192.168.1.5

关系型拼接 join

默认按首列拼接,首列一样的才会拼接

$ cat uuid_ip
459A978D-84D1-4822-BE61-394669D229C5    192.168.1.1
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D    192.168.1.2
90B4D95C-7F0C-4946-8C02-3A43367CC795    192.168.1.3
1FDA8320-57AB-4446-AC48-86C9AE22255B    192.168.1.4
D5F2D01A-9E32-4C9D-A795-07DC50425ACA    192.168.1.5

$ cat uuid_pass
459A978D-84D1-4822-BE61-394669D229C5    qwerljqkbdv
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D    nvqlkewsdgn
90B4D95C-7F0C-4946-8C02-3A43367CC795    eqlfqweg
1FDA8320-57AB-4446-AC48-86C9AE22255B    123123
D5F2D01A-9E32-4C9D-A795-07DC50425ACA    123456

$ join uuid_ip uuid_pass
459A978D-84D1-4822-BE61-394669D229C5 192.168.1.1 qwerljqkbdv
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D 192.168.1.2 nvqlkewsdgn
90B4D95C-7F0C-4946-8C02-3A43367CC795 192.168.1.3 eqlfqweg
1FDA8320-57AB-4446-AC48-86C9AE22255B 192.168.1.4 123123
D5F2D01A-9E32-4C9D-A795-07DC50425ACA 192.168.1.5 123456

指定按哪一列拼接

$ cat ip_uuid
192.168.1.1 459A978D-84D1-4822-BE61-394669D229C5
192.168.1.2 5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D
192.168.1.3 90B4D95C-7F0C-4946-8C02-3A43367CC795
192.168.1.4 1FDA8320-57AB-4446-AC48-86C9AE22255B
192.168.1.5 D5F2D01A-9E32-4C9D-A795-07DC50425ACA

$ cat pass_uuid
qwerljqkbdv 459A978D-84D1-4822-BE61-394669D229C5
nvqlkewsdgn 5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D
eqlfqweg    90B4D95C-7F0C-4946-8C02-3A43367CC795
123123  1FDA8320-57AB-4446-AC48-86C9AE22255B
123456  D5F2D01A-9E32-4C9D-A795-07DC50425ACA

$ join -1 2 -2 2 ip_uuid pass_uuid
459A978D-84D1-4822-BE61-394669D229C5 192.168.1.1 qwerljqkbdv
5FB8CE6F-1E09-42A9-8A7E-AB4D2030C43D 192.168.1.2 nvqlkewsdgn
90B4D95C-7F0C-4946-8C02-3A43367CC795 192.168.1.3 eqlfqweg
1FDA8320-57AB-4446-AC48-86C9AE22255B 192.168.1.4 123123
D5F2D01A-9E32-4C9D-A795-07DC50425ACA 192.168.1.5 123456

weinxin
公众号
扫码订阅最新深度技术文,回复【资源】获取技术大礼包
Linux最后更新:2020-8-31
小熊