I don't have much experience in shell scripting & have a urgent scripting job to complete. Need your help to do the following.
I have a input file like below:
CDR #1
----------
Name James
Age 30
Country Japan
CDR #2
----------
Name Robin
Age 31
Country Germany
CDR #3
----------
Name George
Age 32
Country Australia
Once again thank you all for the help. The input file is now changed by the customer. I am attaching the actual input file. Following is the snippet from the file.
Each CDR should be in a separate line. The script should be able to count the total number of CDR# in the file & genearte CDR as mentioned above for all the CDR's.
It should ignore the below and writes the fabricated data into newfile.dat file. delete the file before running this script else it would append to the same.
3 things still needed in the script.
A] The script should ignore the lines:
listOfTrafficVolumes
qosNegotiated
B] One of the parameter in Filed 1 is Alloc./Retention priority. It contains a ./ & it should not affect script processing.
C] The script should be able to display the following type of values properly.
The output of the lenght field should be '0x0C (12)'. But it is coming only as 0x0C & after that the rest of the output is not as expected. The rest of the fields after that have output in similar format like '0x1 (Delay class 1)' , '0x3 (Unack. GTP/LLC, Ack. RLC, Protected data)' etc.
hope this should fix your issue , as there are lot of white space between the field values I have hard coded the columns to replace with null so change accordingly as per your request if you want to add new columns in the output list , output will be saved in Output.txt.
#!/bin/ksh
sed 's/^[ \t]*//' cdr.txt > cdr_1.txt
sed '/^$/d' cdr_1.txt > cdr_2.txt
sed -e 's/^[ \t]*//' cdr.txt -e '/^$/d' cdr_1.txt > cdr_2.txt
for i in `grep -n "CDR" cdr_2.txt |awk -F ':' '{print $1}'`
do
i=`expr $i + 2`
idx=`expr $i + 25`
a=`sed -n "$i","$idx"p cdr_2.txt|sed -e s/recordType// -e s/servedIMSI// -e s/ggsnAddress// -e s/chargingID// -e s/sgsnAddress// -e s/accessPointNameNI// -e s/pdpType// -e s/servedPDPAddress// -e s/dynamicAddressFlag// -e s/listOfTrafficVolumes// -e s/qosNegotiated// -e s/Length// -e s/"Alloc.\/Retention priority"// -e s/"Delay class"// -e s/"Reliability class"// -e s/"Peak throughput"// -e s/"Precedence class"// -e s/"Mean throughput"// -e s/"Traffic class"// -e s/"Delivery order"// -e s/"Delivery of erroneous SDU"// -e s/"Maximum SDU size"// -e s/"Max bit rate for uplink"// -e s/"Max bit rate for downlink"// -e s/"Residual BER"// -e s/"SDU error ratio"// |sed 's/^[ \t]*/\|/'|tr "\n" " "`
if [ ! -z "$a" ]
then
len=`expr length "$a"`
a=`expr substr "$a" 2 $len`
echo $a >>Output.txt
fi
done
EGSNPDPRECORD|405150016945607|115.255.8.82|626709187|220.224.141.18|rcomwap|IPV4|10.88.79.121|TRUE|0x0C (12)|0x01 (1)|0x1 (Delay class 1)|0x3 (Unack. GTP/LLC, Ack. RLC, Protected data)|0x04 (Up to 8000 oct/s)|0x1 (High priority)|0x1F (Best effort)|0x3 (Interactive class)|0x2 (Without delivery order ('no'))|0x1 (No detect ('-'))|0x96 (1500 octets)|0x40 (64 kbps)|0x40 (64 kbps)|0x4 (1/250 = 4x10^-3)|0x4 (1/10 000 = 1x10^-4)|0x0A (100 ms)|0x1 (Priority level 1)|0x00 (Subscribed maximum bitrate)|0x00 (Subscribed maximum bitrate)|560|15045|Record Closure|110405121501+0530|110405121439+0530|22|Normal Release|GM2|259437517|MS or Network Provided and Subscription Verified|919022552905|Prepaid|SGSN Supplied|405, 15|3593360370770742|GERAN|+08:02|405, 15,15071,31851|10|2g.prepaid|2001|1|110405121443+0530|110405121458+0530|15|PDP context release|01 0b 41 1f 71 96 40 40 44 29 00 00|220.224.141.18|405, 15|560|15045|110405121501+0530|GERAN|
Best Regards,
Sunil
---------- Post updated at 11:30 AM ---------- Previous update was at 11:12 AM ----------
Hi,
This code is also giving the output as desired. Only issue is that it is processing all CDR's twice i.e. My input file had 8 CDR's & the output file had the 8 CDR's followed by 8 CDR's again.
Following is my script.
[root@FLPROVP01 cdr]# cat cat cdr_script_2.sh
cat: cat: No such file or directory
#!/bin/ksh
sed 's/^[ \t]*//' cdr.txt > cdr_1.txt
sed '/^$/d' cdr_1.txt > cdr_2.txt
sed -e 's/^[ \t]*//' cdr.txt -e '/^$/d' cdr_1.txt > cdr_2.txt
for i in `grep -n "CDR" cdr_2.txt |awk -F ':' '{print $1}'`
do
i=`expr $i + 2`
idx=`expr $i + 25`
a=`sed -n "$i","$idx"p cdr_2.txt|sed -e s/recordType// -e s/servedIMSI// -e s/ggsnAddress// -e s/chargingID// -e s/sgsnAddress// -e s/accessPointNameNI// -e s/pdpType// -e s/servedPDPAddress// -e s/dynamicAddressFlag// -e s/listOfTrafficVolumes// -e s/qosNegotiated// -e s/Length// -e s/"Alloc.\/Retention priority"// -e s/"Delay class"// -e s/"Reliability class"// -e s/"Peak throughput"// -e s/"Precedence class"// -e s/"Mean throughput"// -e s/"Traffic class"// -e s/"Delivery order"// -e s/"Delivery of erroneous SDU"// -e s/"Maximum SDU size"// -e s/"Max bit rate for uplink"// -e s/"Max bit rate for downlink"// -e s/"Residual BER"// -e s/"SDU error ratio"// |sed 's/^[ \t]*/\|/'|tr "\n" " "`
if [ ! -z "$a" ]
then
len=`expr length "$a"`
a=`expr substr "$a" 2 $len`
echo $a >>Output.txt
fi
done
[root@FLPROVP01 cdr]#