以前写过一篇文章,是处理2个文件某一域相同或不相同,这次要复杂一点,是匹配关系。
cat 1.txt
/p1/18/27/70891221.jpg
/p1/23/11/70624037.jpg
cat 2.txt
222.210.X.X - - [07/Oct/2013:09:15:22 +0800] "GET /leImage?&url=http://service-img//p1/26/21/70968171.jpg&w=300&h=300&c=0&o=0 HTTP/1.1" 200 15977 "-" "-" 253
80.114.X.X - - [07/Oct/2013:09:30:35 +0800] "GET /leImage?&url=http://service-img//p1/23/11/70624037.jpg&w=125&h=125&c=0&o=0 HTTP/1.1" 200 10299 "-" "-" 226
awk 'NR==FNR{a[$0]}NR>FNR{if(substr($7,index($7,"/p1/"),index($7,"&w=")-index($7,"/p1/")) in a){print $7}}' 1.txt 2.txt
结果:
/leImage?&url=http://service-img//p1/23/11/70624037.jpg&w=125&h=125&c=0&o=0
转载于:https://blog.51cto.com/chenwenming/1307196