linux diff求两个文件的差集
  s88NQinw4PZK 2023年11月30日 26 0

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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月30日 0

暂无评论

推荐阅读
s88NQinw4PZK