Hello Friends,
I'm trying something hard (for me) to create a report script,normally the following script works:
Echos are just for cosmetic touch,
echo -n "\n-----\t----------\t-------------\t\t--------------\t\t--------\n
COUNT\tEVENT_TYPE\tRESPONSE_CODE\t\tINTERNAL_ERROR\t\tFLOWNAME
\n-----\t----------\t-------------\t\t--------------\t\t--------------------------------\n"
&& gzcat *2016-03-29_*gz | gawk -F"|" '
BEGIN{format = "%-10s\t%-8s\t%-14s\t%-32s\n"}{if(( $5 == 2001 )&&( $8 != 0 )&&( $9 != 0 )&&( $12 ~ "fulfillService" ))
printf format, "\t"$5"\t",$8"\t\t",$9"\t",$(NF-1)}' | sort | uniq -c
&& echo -n "-----\t----------\t-------------\t\t--------------\t\t--------------------------------\n"
Output:
----- ---------- ------------- -------------- --------
COUNT EVENT_TYPE RESPONSE_CODE INTERNAL_ERROR FLOWNAME
----- ---------- ------------- -------------- --------------------------------
4506 2001 -3 114 refillVoucherless
11472 2001 -3 115 refillVoucherless
12 2001 -4 11111 addAndActivateService
4 2001 -4 13 setHLRSub
----- ---------- ------------- -------------- --------------------------------
I need to add up extra field to output as "OFFER NAME"
this output will come from 14th field of input files (pipe seperated) after stripping them by using SED and when I run the following command it works; it fetches what I want:
nawk -F\| '{if(( $5 == 2001 ) && ( $8 != 0 ) && ( $9 != 0 ) && ( $12 ~ "fulfillService" ) print $14}' infile
| sed 's#.*\(externalofferid":"\)\(.*\)\(","receiversubscriber\).*#\2#'
gives something like:
ABC_OFFER
Desired Outout is :
----- ---------- ---------- ------------- -------------- --------
COUNT OFFER_NAME EVENT_TYPE RESPONSE_CODE INTERNAL_ERROR FLOWNAME
----- ---------- ---------- ------------- -------------- ---------------------
4506 AAA 2001 -3 114 refillVoucherless
11472 BBB 2001 -3 115 refillVoucherless
12 CCC 2001 -4 11111 addAndActivateService
4 2001 -4 13 setHLRSub
----- ---------- ---------- ------------- -------------- -----------------------
However when I want to add it to the whole command above it fails
I though I had to use a system command (but i'm not sure)
could you please suggest/correct the command?
I tried (did not show echoes part; its already confusing):
gzcat *2016-03-29_*gz | gawk -F"|" '
BEGIN{format = "%-20s\t%-10s\t%-8s\t%-14s\t%-32s\n"}{if(( $5 == 2001 )&&( $8 != 0 )&&( $9 != 0 )&&( $12 ~ "fulfillService" ))
sprintf offer==system("sed 's@.*\(externalofferid":"\)\(.*\)\(","receiversubscriber\).*@\2@'"$14) ;
printf format, "\t"offer"\t"$5"\t",$8"\t\t",$9"\t",$(NF-1)}' | sort | uniq -c
I believe I don't need sprintf as it prints the stripped string..
error:
gawk:
^ syntax error
Thanks in advance.