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 shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2020-10-24 linux系统中配置磁盘容量配额服务(quota)
2020-10-24 linux系统中添加swap交换分区、删除swap交换分区