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 @ 2023-11-10 15:49  HaimaBlog  阅读(57)  评论(0编辑  收藏  举报