linux diff求两个文件的差集

awk 从文本中过滤出需要的ip

queryId_20231109214653_ipBatchQueryResult.json

{"id":0,"ip":"121.204.216.130","type":1,"domain":"","agreement":"","mode":"","postalCode":"102200","longitude":"116.301434","latitude":"40.089029","xCoordinate":"","yCoordinate":"","timeZone":"UTC+8","organization":"中国教育网","ipOperator":"中国教育网","asn":"4538","country":"中国","continent":"亚洲","province":"北京市","city":"北京市","district":"昌平区","scene":"企业专线","geoGraphyPosition":"北京市-北京市-昌平区","ipPositionMode":"算法定位","address":"北京市-北京市-昌平区"}
{"id":0,"ip":"121.204.216.131","type":1,"domain":"","agreement":"","mode":"","postalCode":"102200","longitude":"116.301434","latitude":"40.089029","xCoordinate":"","yCoordinate":"","timeZone":"UTC+8","organization":"中国教育网","ipOperator":"中国教育网","asn":"4538","country":"中国","continent":"亚洲","province":"北京市","city":"北京市","district":"昌平区","scene":"企业专线","geoGraphyPosition":"北京市-北京市-昌平区","ipPositionMode":"算法定位","address":"北京市-北京市-昌平区"}

过滤数据

$ tail -n 1 queryId_20231109214653_ipBatchQueryResult.json | awk -F '{"id":0,"ip":"' '{print $2}' | awk -F '","type' '{print $1}'
152.136.16.211

diff求两个文件的差集

sourceIP.txt中有,resultIP.txt中没有的数据

sourceIP.txt

acb
dd
111
ccc
222
333
444
555
666
777

resultIP.txt

111
222
333
000

求差集

$ diff <(grep "" sourceIP.txt) <(grep "" resultIP.txt) | grep "< *"| awk -F "< " '{print $2}'
acb
dd
444
555
666
777
posted @   HaimaBlog  阅读(58)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2021-11-10 python 操作xls
2021-11-10 python—CSV的读写
2021-11-10 在python中安装包出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
2020-11-10 docker 安装 kafka+zookeeper,golang操作kafka
2020-11-10 VMware安装Centos7超详细过程(图文)
2019-11-10 安装echo框架
2019-11-10 gin框架博客实战教程2019web页面开发go语言实战博客开发
点击右上角即可分享
微信分享提示