我的CSV文件的数据格式如下:
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|SOCIAL|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|EMAIL|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|STREAMING|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|WEB|||10180|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|IM_AND_VOIP|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|DEFAULT|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|TUNNELING|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|FREETRAFFIC|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
201212998474|201212998474|99|20140911092720|1410427640|Sy-module-1.PTS-DR1.mobinil.net;1410427618;0;10.56.201.79|2001|||0|||||mobinildpi|ALWAYS_ON|||0|DIAMETER_LOGOUT||0,0,0,5634026,|201212998474NonRoaming,201212998474_2190_MONTHLY_1GB_20LE,201212998474_7702_Unlimited_CAP,201212998474_7702_POST_FUP_USAGE,|10||T|1|||||
我需要在第22列中提取4个值,并获得列中每个值的第一个读数和最后一个读数之间的差异。 我正在尝试这段代码:
awk -F "|" '{
if (length(msisdn[$1] == 0)) {
msisdn[$1] = $6 ;
counter[$1] = $22 ; }
last[$1] = $22 ;
type[$1] = $23 ;
} END { for ( i in msisdn ) { print i " : " msisdn[i] " : " type[i] " : " (counter [i]-last[i]) ; }}' 201409* > counters.txt
但它只为列中的第一个值提供了所需的输出。 预期的输出应该是这样的:
201274971010 : Sy-ptsd-3.module-3.PTS1-DRC.mobinil.net;1410748407;0;10.215.43.213 : 201274971010NonRoaming,201274971010_2190_MONTHLY_1GB_20LE, : 0 , 320
201202999478 : Sy-ptsd-3.module-8.PTS3-DRC.mobinil.net;1410753394;0;10.141.241.65 : 201202999478NonRoaming,201202999478_2190_MONTHLY_1GB_20LE, : 0 , 150
答案 0 :(得分:0)
短(最短!)答案是
awk -F\| '{
# split(source, destination, separator_re)
split($22, values, /,/);
print values[4]-values[1];
}'
我认为您可以安排其余的输出文件要求(我无法理解)