join:按照两个文件的相同字段合并
简介 join命令针对每一对具有相同内容的行整合为一行,默认情况下是把输入的第一个字段作为连接字段,字段之间用空格隔开。
说明
join命令针对每一对具有相同内容的行整合为一行,默认情况下是把输入的第一个字段作为连接字段,字段之间用空格隔开。
格式
join [option] [file1] [file2]
常用参数说明
- -a 文件号:输出文件中不匹配的行,文件号可选值为1或2,分表表示文件1或文件2
- -i:比较时忽略大小写
- -1 字段:以第一个文件的指定字段为基础进行合并
- -2 字段:以第二个文件的指定字段为基础进行合并
示例
1、对两个文件进行合并
[root@localhost ~]# cat join1.txt
xiaohai 21
zhang 22
li 29
wang 33
[root@localhost ~]# cat join2.txt
wang beijing
zhang shanghai
li chengdu
xiaohai taikong
[root@localhost ~]# join join1.txt join2.txt #合并的时候,要求对这两个文件先进行排序
join: join1.txt:3: is not sorted: li 29
join: join2.txt:3: is not sorted: li chengdu
zhang 22 shanghai
li 29 chengdu
[root@localhost ~]# sort join1.txt > join1.txts
[root@localhost ~]# sort join2.txt > join2.txts
[root@localhost ~]#
[root@localhost ~]# cat join1.txts
li 29
wang 33
xiaohai 21
zhang 22
[root@localhost ~]# cat join2.txts
li chengdu
wang beijing
xiaohai taikong
zhang shanghai
[root@localhost ~]#
[root@localhost ~]# join join1.txts join2.txts #排序后的文件进行合并
li 29 chengdu
wang 33 beijing
xiaohai 21 taikong
zhang 22 shanghai
2、-i参数使用,忽略大小写
[root@localhost ~]# vim join2.txt #将zhang改成Zhang
[root@localhost ~]# sort join2.txt > join2.txts #重新排序
[root@localhost ~]# cat join2.txts
li chengdu
wang beijing
xiaohai taikong
Zhang shanghai
[root@localhost ~]#
[root@localhost ~]# join -i join1.txts join2.txts
li 29 chengdu
wang 33 beijing
xiaohai 21 taikong
zhang 22 shanghai
3、指定按照某个字段进行合并
[root@localhost ~]# cat join1.txt #修改该文件,在前面加上一列序号
1 xiaohai 21
2 zhang 22
3 li 29
4 wang 33
[root@localhost ~]# sort -t " " -k 2 join1.txt > join1.txts #按照第二列进行排序,并写入到新文件
[root@localhost ~]# join join1.txts join2.txts -1 2 #指定第一个文件的第二个字段
li 3 29 chengdu
wang 4 33 beijing
xiaohai 1 21 taikong
打包出现如下错误:Error: Application entry file "dist\electron\main.js" in the "D:\gui\demo2\build\win-unpacked\resources\app.asar" does not exist. Seems like a wrong configuration.
在使用功能镜像的时候,需要对时区进行修改,那么就需要从两个方面来考虑,本文主要记录Dockerfile和docker-compose.yml设置时区。
桌面应用很多都会在系统托盘中出现,那么Flutter的开发的桌面应用该如何增加到系统托盘中呢?本文将带大家一起尝试一下.
Ansible-tower工具搭建和使用
SkyWalking是一个开源的观测平台,用于从服务和云原生等基础设施中收集、分析、聚合以及可视化数据。SkyWalking 提供了一种简便的方式来清晰地观测分布式系统,甚至可以观测横跨不同云的系统。SkyWalking 更像是一种现代的应用程序性能监控(Application Performance Monitoring,即APM)工具,专为云原生,基于容器以及分布式系统而设计。
快速生成表格
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题