linux中实现两个文件按照指定列合并

 

001、 提取两个文件中指定列相同的行

复制代码
[root@pc1 test01]# ls
file1  file2
[root@pc1 test01]# cat file1
a rs1
b rs2
c rs4
[root@pc1 test01]# cat file2
a 0.170721 -1.82031 0.0690841 rs1
b 0.0803412 -1.01669 0.309605 rs2
c 0.21245 0.22964 0.81843 rs3
d 0.0707158 -0.499683 0.617435 rs4
[root@pc1 test01]# awk 'NR == FNR {ay[$2]; next} $NF in ay' file1 file2
a 0.170721 -1.82031 0.0690841 rs1
b 0.0803412 -1.01669 0.309605 rs2
d 0.0707158 -0.499683 0.617435 rs4
复制代码

 

002、 提取file2中唯一的行

复制代码
[root@pc1 test01]# ls
file1  file2
[root@pc1 test01]# cat file1
a rs1
b rs2
c rs4
[root@pc1 test01]# cat file2
a 0.170721 -1.82031 0.0690841 rs1
b 0.0803412 -1.01669 0.309605 rs2
c 0.21245 0.22964 0.81843 rs3
d 0.0707158 -0.499683 0.617435 rs4
[root@pc1 test01]# awk 'NR == FNR {ay[$2]; next} !($NF in ay)' file1 file2
c 0.21245 0.22964 0.81843 rs3
复制代码

 

 

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

 

posted @   小鲨鱼2018  阅读(610)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-09-13 linux 中磁盘容量配额
2022-09-13 linux 中如何查看磁盘剩余空间的总大小
2020-09-13 使用KMSTools 激活 windows10 专业版
点击右上角即可分享
微信分享提示