2018-05-11 awk按照指定内容匹配按照行合并两个文件

终于初步实现了效果:
nid30_0507_rm.txt 为 7个转化日志,nid30_0507_rm_clicktoconver.txt 为14行,每两行中第一行是点击的clickid,第二行是点击日志。
现在要把nid30_0507_rm_clicktoconver.txt中点击clickid替换成转化日志,达到快速查看效果。

下面的不加 NR!=FNR结果真的不一样(不加就显示21行,等同于cat合并两个文件)!加了表示只在读取第二个文件时print 内容。不加else也是显示21行(结果还可以接受。等同于每三行描述一个转化对应的点击。就是把转化日志插入到clickid和点击日志的上面.没有else表示输出第二个文件的所有行,所以没有删除只有clickid的行)。

2721 $ awk -F"|" 'NR==FNR{a[$1]=$0};NR!=FNR{if($0 in a)print a[$0];else print $0}' nid30_0507_rm.txt nid30_0507_rm_clicktoconver.txt|nl

 1  10a32fbb2a124f1006f667947dfda00b|30|334459|0.2|0.21|US|0|1|150|474|com.turbochilli.rollingsky|10150_mg9891_11181_107|34.238.251.230|0|0|0||||1525696910|1525698389
 2  click20180507124:30|334459|0|34.238.251.230|US|150|474|com.turbochilli.rollingsky|0.200|10a32fbb2a124f1006f667947dfda00b|2d01c85c-0c1e-402b-9156-459d83f74aa2|10150_mg9891_11181_107|%#base64#%MjAxODA1MDcyMDQxNDk0ODA1OTUzYQ==||1|0|0|0|0|||1525696910
 3  a031fb628a9f1f5a595e86c988e6ec83|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_11757_108_a1b2|172.58.141.187|0|0|0||||1525702128|1525702171
 4  click20180507140:30|591707|0|172.58.141.187|US|150|437|com.immobilegames.skidstorm|0.150|a031fb628a9f1f5a595e86c988e6ec83|1e91cf03-4d80-43cc-8f38-1f39fbc55636|10150_mg9891_11757_108_a1b2|%#base64#%MjAxODA1MDcyMjA4NDcyMjA1MjAzYQ==||1|0|0|0|0|||1525702128
 5  8da284fd62af425245057b13d0a3e5c3|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_11757_108_a1b2|99.51.176.26|0|0|0||||1525702973|1525703354
 6  click20180507142:30|591707|0|99.51.176.26|US|150|437|com.immobilegames.skidstorm|0.150|8da284fd62af425245057b13d0a3e5c3|e4efa08d-005d-48a8-9b17-03e48ab35f7c|10150_mg9891_11757_108_a1b2|%#base64#%MjAxODA1MDcyMjIyNTAyMTAzODE5YQ==||1|0|0|0|0|||1525702973
 7  74bd0d05f415be4d9ed933c4fdfac530|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_11757_108_a1b2|209.122.195.66|0|0|0||||1525703513|1525703921
 8  click20180507143:30|591707|0|209.122.195.66|US|150|437|com.immobilegames.skidstorm|0.150|74bd0d05f415be4d9ed933c4fdfac530|ae26af26-6761-4fd7-bd76-b19b271dbdaa|10150_mg9891_11757_108_a1b2|%#base64#%MjAxODA1MDcyMjMxNTI0NTA3NDE2YQ==||1|0|0|0|0|||1525703513
 9  87a975d2a129b4f4334bb234f11198f1|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_11757_108_a1b2|136.62.248.36|0|0|0||||1525704128|1525704338
10  click20180507144:30|591707|0|136.62.248.36|US|150|437|com.immobilegames.skidstorm|0.150|87a975d2a129b4f4334bb234f11198f1|2065be4d-3dc1-4a57-bc48-ea4d1db79a1e|10150_mg9891_11757_108_a1b2|%#base64#%MjAxODA1MDcyMjQyMDgyMTA3NDM4YQ==||1|0|0|0|0|||1525704128
11  3029db1d817b0ef345321e528b705c2d|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_11757_108_a1b2|75.71.58.41|0|0|0||||1525704129|1525704451
12  click20180507144:30|591707|0|75.71.58.41|US|150|437|com.immobilegames.skidstorm|0.150|3029db1d817b0ef345321e528b705c2d|21e07a68-9370-4912-a5df-3cb919c8e8e4|10150_mg9891_11757_108_a1b2|%#base64#%MjAxODA1MDcyMjQyMDg0NDA5MzYwYQ==||1|0|0|0|0|||1525704129
13  341dd7fc62ba82c721dce201ec72c71c|30|591707|0.15|0.158|US|0|1|150|437|com.immobilegames.skidstorm|10150_mg9891_10739_|68.55.8.110|0|0|0||||1525731157|1525731451
14  click20180507221:30|591707|0|68.55.8.110|US|150|437|com.immobilegames.skidstorm|0.150|341dd7fc62ba82c721dce201ec72c71c|0b1fc2b3-cc61-4cef-975c-91217de0d3ae|10150_mg9891_10739_|%#base64#%MjAxODA1MDgwNjEyMzc0NDA3OTUyYQ==||1|0|0|0|0|||1525731157

你可能感兴趣的:(2018-05-11 awk按照指定内容匹配按照行合并两个文件)