你有两列数 分别在两个文件里面
现在你用其中一列去乘另外一列

前提是
第一列的第一个数 乘以 第二列的 5个数
第一列的第二个数 乘以 第二列的 6-10 个数

以此类推, 不要求计算结果,只要求能写出循环就可以了

 

 

 

awk 'BEGIN{i=1}NR==FNR{a[NR]=$0;next}{print a[i]"*"$0}!(FNR%5){i++}' a b

 awk 'BEGIN{i=1}NR==FNR{a[NR]=$0;next}{print a[i]"*"$0"="a[i]*$0}!(FNR%5){i++}

' a b    //打印出结果

 

例子2:

2012-03-20 00:10:04,609|in|290159771|50441|1|1

2012-03-20 00:10:04,628|in|1943176883|184774|1|1

2012-03-20 00:10:04,636|in|1451761039|119524|1|1

2012-03-20 00:10:57,163|in|535519044|130111|1|1

2012-03-20 00:11:16,116|in|539925022|190121|1|1

2012-03-20 00:11:30,594|in|539925022|190124|1|1

2012-03-20 00:11:36,324|out|851884810|187746|1|1|1316

2012-03-20 00:11:45,774|in|539923758|190118|1|1

2012-03-20 02:24:02,569|in|1576181709|128520|1|1

2012-03-20 02:24:30,954|out|1171594618|191187|1|1|0

2012-03-20 02:26:21,004|out|2350653726|187332|1|1|263

2012-03-20 02:27:31,031|out|1187829475|85589|1|1|7373

2012-03-20 02:27:51,046|out|729727233|40126|1|1|134

2012-03-20 02:28:21,070|out|674875797|187027|1|1|912

2012-03-20 02:30:31,128|out|2313978041|185783|1|1|211

2012-03-20 02:32:26,987|in|938528073|104368|1|1

2012-03-20 02:32:31,190|out|1962118343|191653|1|1|12

2012-03-20 02:32:31,191|out|1510226903|141178|1|1|61

2012-03-20 02:35:21,264|out|461916055|113456|1|1|24

2012-03-20 02:35:31,267|out|707832452|171721|1|1|0

2012-03-20 02:36:51,310|out|1227931884|107351|1|1|720

2012-03-20 02:37:41,337|out|947278889|0|1|1|0

2012-03-20 02:37:48,608|in|2568794018|142620|1|1

2012-03-20 02:38:25,892|in|947278889|0|1|1

2012-03-20 02:38:41,364|out|243153026|111029|1|1|181

2012-03-20 02:39:01,376|out|709678156|53142|1|1|2213

2012-03-20 02:39:11,380|out|1576181709|128520|1|1|0

2012-03-20 02:39:11,381|out|329281132|190850|1|1|1200

2012-03-20 02:39:41,395|out|947278889|135322|1|1|321

2012-03-20 00:02:46,052|out|5796186|191619|1|1|119

2012-03-20 00:02:47,956|in|870631023|20674|1|1

2012-03-20 00:03:36,088|out|1131799010|128185|1|1|99

2012-03-20 00:03:36,090|out|539925022|190121|1|1|215

2012-03-20 00:03:54,138|in|1455314828|190951|1|1

2012-03-20 00:04:16,104|out|102760701|183901|1|1|39

2012-03-20 00:04:24,405|in|243153026|111029|1|1

2012-03-20 00:04:26,111|out|707832452|171721|1|1|918

2012-03-20 00:04:57,138|in|1227931884|107351|1|1

2012-03-20 00:05:06,127|out|102760701|183902|1|1|9

2012-03-20 00:05:20,131|in|946303259|143820|1|1

2012-03-20 00:05:26,138|out|291156509|133743|1|1|15

2012-03-20 00:06:06,154|out|290159771|50441|1|1|36

2012-03-20 00:06:21,662|in|1275036956|190947|1|1

2012-03-20 00:06:27,022|in|931590408|21480|1|1

2012-03-20 00:06:41,553|in|1058498372|86299|1|1

2012-03-20 00:06:56,177|out|1107678229|97277|1|1|10

2012-03-20 00:07:06,184|out|912973184|128277|1|1|51

2012-03-20 00:07:09,965|in|2502666580|191193|1|1

2012-03-20 00:07:36,208|out|1374914251|124675|1|1|1095

2012-03-20 00:08:06,224|out|835860801|167559|1|1|444

2012-03-20 00:08:06,225|out|188871300|187329|1|1|11

2012-03-20 00:08:36,239|out|173524377|2795|1|1|26

2012-03-20 00:09:32,366|in|1187829475|85589|1|1

2012-03-20 00:10:04,609|in|290159771|50441|1|1

2012-03-20 00:10:04,628|in|1943176883|184774|1|1

2012-03-20 00:10:04,636|in|1451761039|119524|1|1

2012-03-20 00:10:57,163|in|535519044|130111|1|1

2012-03-20 00:11:16,116|in|539925022|190121|1|1

2012-03-20 00:11:30,594|in|539925022|190124|1|1

2012-03-20 00:11:36,324|out|851884810|187746|1|1|1316

 

 

我现在需要统计出每个小时登入登出的id数

第三列是玩家id,in是登入,out是登出

 

awk -F"[:|]" '{b[$1]=$4;if(!a[$1]){a[$1]=$1;if(b[$1]=="in"){i[$1]=1}else{j[$1]=1}}else{if(b[$1]=="in"){i[$1]++}else{j[$1]++}}}END{for(z in a){print a[z],"in",i[z],"out",j[z]}}' test.txt