- 论坛徽章:
- 0
|
主要是处理计费话单,文件大的话达到500万行,可用的话单大概8万条左右,我的思路是将原始话单按照个人需要的计费类别进行分割,每2000个需要的记录生成一个文件,然后再在这些文件中按照每一条记录再生成1999个文件,最终提取所需要的字段,感觉执行起来非常慢,麻烦各位帮小弟看一下了,谢谢先。附上原始程序和部分话单
程序执行:./bill_main.sh test.data
----------------------------------
bill_main.sh
#!/bin/sh
rm -fr tmp_file/Bill_RPT.txt
v_file_in=$1
./bill_pre.sh $1
file_total=`ls -l file*|wc|awk '{print $1}'`
j=1
for i in `ls file*`
do
echo "There Are Total $file_total Raw Records,Current Executing Record is $j"
./bill_body.sh $i
let j=$j+1
done
rm -fr file* row_test*
------------------------------------
bill_pre.sh
#!/bin/sh
v_file_input=$1
rm -fr file* row_$v_file_input
v_rows=`grep "CDR GATE" $v_file_input |wc -l`
v_rows_total=`cat $v_file_input |wc -l`
v_times=`expr $v_rows / 2000`
grep -n "CDR GATE" $v_file_input >row_$v_file_input
i=0
init_rows=0
v_rows_start=1
while [ $i -lt $v_times ]
do
let i=$i+1
init_rows=`expr $init_rows + 2000`
v_rows_end=`cat row_$v_file_input|head -n $init_rows|tail -n 1|awk -F":" '{print $1}'`
v_rows_end_tmp=`expr $v_rows_end - 1`
sed -n "$v_rows_start,$v_rows_end_tmp"p $v_file_input>"file"$i
v_rows_start=$v_rows_end
done
sed -n "$v_rows_start,$v_rows_total"p $v_file_input>fileLast
----------------------------------
bill_body.sh
#!/bin/sh
v_file_in=$1
dos2unix -q $1
rm -fr tmp_file/Raw*
rm -fr tmp_file/Result.txt
awk -F" " 'begin{i=0}{if($0~/^[0-9]+ CDR GATE/){i=i+1}else print $0>>"tmp_file/Raw1_"i".txt"}' $1
cd tmp_file
for i in `ls Raw1_*`
do
v_callingNumber_tmp=`sed -n '/callingNumber{/,/\}/p' $i|grep -i "isdn="|awk -F"=" '{print $2}'|head -1|sed 's/\n//g'`
v_calledNumber=`sed -n '/calledNumber{/,/\}/p' $i|grep -i "isdn="|awk -F"=" '{print $2}'|head -1|sed 's/\n//g'`
v_RedirNumber=`sed -n '/RedirNumber{/,/\}/p' $i|grep -i "isdn="|awk -F"=" '{print $2}'|head -1|sed 's/\n//g'`
v_timeForAnswer=`grep -i 'timeForAnswer' $i|awk -F"=" '{print $2}'|sed 's/[-: ]//g'|head -1|sed 's/\n//g'`
v_timeForRelease=`grep -i 'timeForRelease' $i|awk -F"=" '{print $2}'|sed 's/[-: ]//g'|head -1|sed 's/\n//g'`
v_incomingTKGP=`grep -i 'incomingTKGP' $i|awk -F"=" '{print $2}'|head -1|sed 's/\n//g'`
v_outgoingTKGP=`grep -i 'outgoingTKGP' $i|awk -F"=" '{print $2}'|head -1|sed 's/\n//g'`
v_callDuration=`grep -i 'callDuration' $i|awk -F"=" '{print $2}'|awk -F"(" '{print $1}'|head -1|sed 's/\n//g'`
v_callingNumber=`echo ${v_RedirNumber:-$v_callingNumber_tmp}|sed 's/\n//g'`
echo "$v_callingNumber|$v_calledNumber|$v_timeForAnswer|$v_timeForRelease|$v_callDuration|$v_incomingTKGP|$v_outgoingTKGP">>Result.txt
done
dos2unix -q Result.txt
sed '/||||||/d' Result.txt >>Bill_RPT.txt
rm -fr Raw* Result.txt
-----------------------------------------------------------------
附上部分test.data
Format: (3G ZTE V3.2)
Begin -- 2010-02-10 09:20:02
End -- 2010-02-10 10:20:00
================================================================================
70 CDR GATEIN={
RecordType=0(GATEIN)
sequenceNumber=5465972
callingNumber{
AddInd=H'2
NumPlan=H'1
ISDN=13882026257832
}
calledNumber{
AddInd=H'2
NumPlan=H'1
ISDN=58309256
}
mscNumber{
AddInd=H'1
NumPlan=H'6
ISDN=460030934020061213
}
incomingTKGP=1156
outgoingTKGP=1031
inTrunkGpModule=10
outTrunkGpModule=0
timeForSeizeChannel=2010-02-10 09:49:14
timeForAnswer=2010-02-10 09:49:36
timeForRelease=2010-02-10 09:49:59
callDuration=23(seconds)
partialOutputRecNum=0
lastPartialOutput(The last CDR)
callReference{
Module=10
SequenceNo=1335006
}
causeForTermination=0(Normal Release)
diagnostics=H'0000
chargedParty=0(Originator Charged)
IsPulseChargeSup=0
}
--------------------------------------------------------------------------------
70 CDR GATEIN={
RecordType=0(GATEIN)
sequenceNumber=5465973
callingNumber{
AddInd=H'2
NumPlan=H'1
ISDN=15870560053381
}
calledNumber{
AddInd=H'2
NumPlan=H'1
ISDN=57650985
}
mscNumber{
AddInd=H'1
NumPlan=H'6
ISDN=4600300934021116100
}
incomingTKGP=1156
outgoingTKGP=1031
inTrunkGpModule=10
outTrunkGpModule=0
timeForSeizeChannel=2010-02-10 09:48:27
timeForAnswer=2010-02-10 09:48:38
timeForRelease=2010-02-10 09:49:59
callDuration=81(seconds)
partialOutputRecNum=0
lastPartialOutput(The last CDR)
callReference{
Module=10
SequenceNo=1334339
}
causeForTermination=0(Normal Release)
diagnostics=H'0000
chargedParty=0(Originator Charged)
IsPulseChargeSup=0
}
--------------------------------------------------------------------------------
70 CDR GATEIN={
RecordType=0(GATEIN)
sequenceNumber=5465974
callingNumber{
AddInd=H'2
NumPlan=H'1
ISDN=13628266001111818
}
calledNumber{
AddInd=H'4
NumPlan=H'1
ISDN=72009738
}
mscNumber{
AddInd=H'1
NumPlan=H'6
ISDN=46003093402600100
}
incomingTKGP=1156
outgoingTKGP=1032
inTrunkGpModule=10
outTrunkGpModule=0
timeForSeizeChannel=2010-02-10 09:49:36
timeForAnswer=2010-02-10 09:49:45
timeForRelease=2010-02-10 09:49:59
callDuration=14(seconds)
partialOutputRecNum=0
lastPartialOutput(The last CDR)
callReference{
Module=10
SequenceNo=1335350
}
causeForTermination=0(Normal Release)
diagnostics=H'0102
chargedParty=0(Originator Charged)
IsPulseChargeSup=0
}
--------------------------------------------------------------------------------
70 CDR GATEIN={
RecordType=0(GATEIN)
sequenceNumber=5465975
callingNumber{
AddInd=H'2
NumPlan=H'1
ISDN=158260025566723
}
calledNumber{
AddInd=H'2
NumPlan=H'1
ISDN=72146103
}
mscNumber{
AddInd=H'1
NumPlan=H'6
ISDN=4600300093664026100
}
incomingTKGP=1156
outgoingTKGP=1032
inTrunkGpModule=10
outTrunkGpModule=0
timeForSeizeChannel=2010-02-10 09:49:09
timeForAnswer=2010-02-10 09:49:18
timeForRelease=2010-02-10 09:50:00
callDuration=42(seconds)
partialOutputRecNum=0
lastPartialOutput(The last CDR)
callReference{
Module=10
SequenceNo=1334937
}
causeForTermination=0(Normal Release)
diagnostics=H'0102
chargedParty=0(Originator Charged)
IsPulseChargeSup=0
}
--------------------------------------------------------------------------------
71 CDR GATEOUT={
RecordType=1(GATEOUT)
sequenceNumber=5465976
callingNumber{
AddInd=H'2
NumPlan=H'1
ISDN=0235893220021859
}
calledNumber{
AddInd=H'2
NumPlan=H'1
ISDN=13668463127
}
mscNumber{
AddInd=H'1
NumPlan=H'6
ISDN=46003093224026100
}
incomingTKGP=1032
outgoingTKGP=1156
inTrunkGpModule=0
outTrunkGpModule=10
timeForSeizeChannel=2010-02-10 09:49:02
timeForAnswer=2010-02-10 09:49:26
timeForRelease=2010-02-10 09:50:00
callDuration=34(seconds)
partialOutputRecNum=0
lastPartialOutput(The last CDR)
callReference{
Module=14
SequenceNo=831460
}
causeForTermination=0(Normal Release)
diagnostics=H'0102
chargedParty=0(Originator Charged)
IsPulseChargeSup=0
}
-------------------------------------------------------------------------------- |
|