Shell中的join用法
Shell中的join用法
将两个文件里指定栏位置同样的行连接起来,
即依照两个文件中共同拥有的某一列,
将相应的行拼成一行(原文件不改变)
内连接(忽略不匹配的行) join file1 file2
显示左边文件中所有记录,右边文件中没有匹配的显示空白
join -a1 file1 file2
显示右边文件中所有记录,左边文件中没有匹配的显示空白
join -a2 file1 file2
全连接(又称全外连接,显示左边和右边所有记录)
join -a1 -a2 file1 file2
指定输出字段
join -o 1.1 file1 file2表示只输出第一个文件的第一个字段
指定输出多个字段
输出第一个文件的第一个字段,输出第二个文件的第二个字段
join - o 1.1 2.2 1.2 file1 file2
指定分隔符
join -t ‘:’ /etc/passwd /etc/shadow
不匹配输出
Join -v 1 -a1 -a2 file1 file2
-v FILENUM:与-a相似,但只显示文件里没有匹配的行
FILENUM : 区分左边还是右边的文件
[root@localhost join]# cat join1
www onmpw
domain jiyi
w3 blog
[root@localhost join]# cat join2
www com
domain cn
w3 net
Join org
wc l
[root@localhost join]# join join1 join2
www onmpw com
domain jiyi cn
w3 blog net
join: join2:6: is not sorted:
[root@localhost join]#
join -t : file.db file_hobby.db #-t 指定分隔符,拼接列相等的行
[root@localhost join]# cat file.db
A li:20:men:anhui
B wang:21:women:jiangsu
C zhang:22:men:anhui
D liu:23:women:Shanghai
E chen:23:women:Hefei
[root@localhost join]# cat file_hobby.db
A li:Song
B wang:shopping
C zhang:pingpong
D liu:chess
E wang:reading
[root@localhost join]# join -t : file.db file_hobby.db
A li:20:men:anhui:Song
B wang:21:women:jiangsu:shopping
C zhang:22:men:anhui:pingpong
D liu:23:women:Shanghai:chess
join内拼接(都是基于join file1 file2的结果)
[root@localhost join]# vim file1
[root@localhost join]# seq 1 1 14 > file1
[root@localhost join]# vim file1
[root@localhost join]# seq 1 1 13 > file2
[root@localhost join]# ls
file1 file2 file.db file_hobby.db join1 join2
[root@localhost join]# cat file1
1 Jan
2 Feb
……
9 Sep
10 Oct
11 Nov
12 Dec
13 MonthUnknow
[root@localhost join]# cat file2
1 一月
2 二月
……
9 九月
10 十月
11 十一月
12 十二月
[root@localhost join]# join file1 file2
1 Jan 一月
2 Feb 二月
……
9 Sep 九月
10 Oct 十月
11 Nov 十一月
12 Dec 十二月
-a2显示右边文件中的所有记录,左边文件中没有匹配的显示空白
左:第一个 右:第二个
[root@localhost join]# join -a2 file2 file1
1 一月 Jan
2 二月 Feb
……
9 九月 Sep
10 十月 Oct
11 十一月 Nov
12 十二月 Dec
13 MonthUnknow
-a1显示左边文件中的所有记录,右边文件中没有匹配的显示空白
[root@localhost join]# join -a1 file2 file1
1 一月 Jan
2 二月 Feb
……
9 九月 Sep
10 十月 Oct
11 十一月 Nov
12 十二月 Dec
-a1 -a2 显示全外连接,显示左边和右边的所有结果
[root@localhost join]# join -a1 -a2 file2 file1
1 一月 Jan
2 二月 Feb
……
9 九月 Sep
10 十月 Oct
11 十一月 Nov
12 十二月 Dec
13 MonthUnknow
以下操作基于join file1 file2的结果
-o a.b 指定文件的字符join file1 file2处理结果后取第a个文件
(默认以空格为分隔符)的第一个字段
[root@localhost join]# join file1 file2
1 Jan 一月
2 Feb 二月
……
9 Sep 九月
10 Oct 十月
11 Nov 十一月
12 Dec 十二月
[root@localhost join]# join -o 1.1 file1 file2
1
2
……
9
10
11
12
[root@localhost join]# cat file1
1 Jan
2 Feb
……
9 Sep
10 Oct
11 Nov
12 Dec
13 MonthUnknow
输出join处理后的第一个文件的第一个字段 第二个文件的第二个字段
[root@localhost join]# join -o 1.1 2.2 file1 file2
1 一月
2 二月
……
9 九月
10 十月
11 十一月
12 十二月
输出join处理后的第一个文件的第一个字段
和第二个文件的第二个字段 和第一个文件的第二个字段
[root@localhost join]# join -o 1.1 2.2 1.2 file1 file2
1 一月 Jan
2 二月 Feb
……
9 九月 Sep
10 十月 Oct
11 十一月 Nov
12 十二月 Dec
[root@localhost join]# join -o 1.1 2.2 1.1 file1 file2
1 一月 1
2 二月 2
……
9 九月 9
10 十月 10
11 十一月 11
12 十二月 12
join -t ':' file1 file2
-t 指定分隔符进行join操作,分隔符被单引号包围
[root@localhost join]# join -t ':' /etc/passwd /etc/shadow
join -v 1 -a1 -a2 file1 file2 输出不匹配的行输出
[root@localhost join]# join -v 1 -a1 -a2 file1 file2
13 MonthUnknow
Shell中的join用法相关推荐
- shell实例第22讲:shell中分隔符IFS用法
shell中分隔符IFS用法 1.什么是IFS? IFS在shell中是分隔符的意思,即IFS这个变量中存放了分隔符. 2.IFS是全局变量还是局部变量? (1)linux中变量分两种:全局变量env ...
- linux 脚本map,shell中map的用法
##实例代码 #!/bin/bash cat ./switchsql.txt | while read line do tmp_partition_name=`echo $line | awk -F ...
- MySQL中Left Join用法
MySQL中Left Join用法 例子: user表: id name --------- 1 libk 2 zyfon 3 daodao user_action表: user_i ...
- Shell中的until用法
Shell中的until用法 基本格式: until CONDITIONdostatementdone 说明: until进入循环的条件是:condition不成立时,就执行循环. ...
- shell 中TR的用法,大小写转化
shell 中TR的用法,大小写转化 1. 用tr 例如:UPPERCASE=$(echo $VARIABLE | tr '[a-z]' '[A-Z]') (把VARIABLE的小写转换成大写)LOW ...
- shell中expect的用法
shell中expect的用法 expect一般用于实现用脚本来自动远程登录,对远程机器执行相关操作 测试机上的expect目录一般在/usr/bin/expect路径 下面是从网上查询的用法总结: ...
- linux bash and,linux bash shell中for的用法and示例
关于linux bash shell中的for语句 在linux中shell是必不可少的一部分,但是在bash shell中有while,for,until等循环命令,今天就介绍一下关于for的一些用 ...
- shell 中的expect 用法
expect一般用于实现用脚本来自动远程登录,对远程机器执行相关操作 测试机上的expect目录一般在/usr/bin/expect路径 下面是从网上查询的用法总结: 1. expect中的判断语句: ...
- shell中的EOF用法
1.EOF Shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主调Shell. 可以把EOF替换成其他东西,意思是把内容 ...
最新文章
- 对于C#里面的this与base
- X Window、GNOME和KDE之间的关系
- python爬取时怎么获取头部header
- shell 循环 read line
- timerpickerview使用_详解iOS App中UIPickerView滚动选择栏的添加方法
- axios 超时_聊聊 Vue 中 axios 的封装
- 重磅分享(二)——决策引擎实战部署
- 前端MVC Vue2学习总结(八)——前端路由
- 私有云落地解决方案之网络篇-网络架构
- nrf52840蓝牙协议栈主机BLE串口
- MySQL中的文本处理函数整理,收藏速查
- Java_08 快速入门 Java常用类库
- 三分钟搭建开源的工单系统ferry
- Win7升为Win10以及win7系统的重装
- 怎么样说一段精彩的一分钟的自我介绍
- 正点原子第四期环境搭建
- 【优化】WIN10 打开文件卡半秒 解决方案
- 个人信用报告内容组成和解读(7) ---公共信息明细
- nginx+lua 实现的免费网站站长工具-防网络爬虫,自动推送百度,批量添加站长统计
- 「谷歌插件」这是一款我认为最好的标签页扩展插件
热门文章
- 西北乱跑娃 --- python爬虫
- 个人计算机和家用计算机的区别,量子计算机与普通计算机的区别?
- NLP分词与词频实现
- oracle数据库字符集AL32UTF8修改为ZHS16GBK即从超集到子集
- 【database】表情识别Cohn-Kanade Database(CK+)
- ISE verilog 综合错误提示:ERROR:Xst:880 - Johnson_source.v line 45: Cannot mix blocking and non blocking
- 王者荣耀吃鸡气泡等等头像框DIY在线生成N种风格微信小程序源码下载
- Android CameraServer:Disconnect
- springbatch读取文件_Spring Batch读取txt文件并写入数据库的方法教程
- Python每日一练(20)-用Python制作mini翻译器