linux系统中comm命令的用法
2021/10/25 7:13:13
本文主要是介绍linux系统中comm命令的用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
linux中comm命令用于提取两列数据中的唯一项、交集、并集等。
1、测试数据
root@PC1:/home/test/test# ls a.txt b.txt root@PC1:/home/test/test# cat a.txt w s g d w a root@PC1:/home/test/test# cat b.txt d a e d t c
2、对数据去重复
root@PC1:/home/test/test# cat a.txt w s g d w a root@PC1:/home/test/test# sort -u a.txt > a && mv a a.txt root@PC1:/home/test/test# cat a.txt a d g s w root@PC1:/home/test/test# cat b.txt d a e d t c root@PC1:/home/test/test# sort -u b.txt > a && mv a b.txt root@PC1:/home/test/test# cat b.txt a c d e t
3、测试使用
root@PC1:/home/test/test# cat a.txt a d g s w root@PC1:/home/test/test# cat b.txt a c d e t root@PC1:/home/test/test# comm a.txt b.txt a c d e g s t w
第一列是a.txt中唯一的项, 第二列是b.txt中唯一的项, 第三列是a.txt和b.txt中共有的项
4、只保留a.txt中唯一的项、 或者b.txt中唯一的项、或者两者交集
root@PC1:/home/test/test# cat a.txt a d g s w root@PC1:/home/test/test# cat b.txt a c d e t root@PC1:/home/test/test# comm a.txt b.txt a c d e g s t w root@PC1:/home/test/test# comm a.txt b.txt -2 -3 g s w root@PC1:/home/test/test# comm a.txt b.txt -1 -3 c e t root@PC1:/home/test/test# comm a.txt b.txt -1 -2 a d
5、取两者并集
root@PC1:/home/test/test# cat a.txt a d g s w root@PC1:/home/test/test# cat b.txt a c d e t root@PC1:/home/test/test# comm a.txt b.txt a c d e g s t w root@PC1:/home/test/test# comm a.txt b.txt | sed 's/^[\t]\+//g' a c d e g s t w
这篇关于linux系统中comm命令的用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-11Linux部署Scrapy学习:入门级指南
- 2024-09-11Linux部署Scrapy:入门级指南
- 2024-08-21【Linux】分区向左扩容的方法
- 2024-08-21【Linux】gnome桌面环境切换KDE Plasma
- 2024-08-19如何安装 VMware Tools (macOS, Linux, Windows)
- 2024-08-15Linux部署Scrapy教程:入门级指南
- 2024-07-29linux命令行下好用的性能监控工具atop
- 2024-07-04Linux系统上离线升级SSH服务的具体操作步骤-icode9专业技术文章分享
- 2024-06-0600-macOS和Linux安装和管理多个Python版本
- 2024-03-30[译]漫画SELinux概念