I have a flat file sort by Phonenumber and Bigin call fileA.txt
Phonnumber|Begin|Endca|D1|D2|Diff
4159061234|10:00|10:01|a1|a2|60
4159061234|10:00|10:06|b1|b2|360
4159061234|10:05|10:06|c1|c2|60
4159061234|10:12|10:15|d1|d2|180
3045678934|10:25|10:28|x1|x2|180
3045678934|10:25|10:30|y1|y2|300
3045678934|10:28|10:31|z1|z2|180
....................
How do I write a code in ksh so it will check the
phone number and if phone number with same begin call then count
and give outout.txt as a result
Phonnumber|Begin|Endca|D1|D2|Call Times
3045678934|10:25|10:28|x1|x2|2
3045678934|10:28|10:31|z1|z2|1
4159061234|10:00|10:01|a1|a2|2
4159061234|10:05|10:06|c1|c2|1
4159061234|10:12|10:15|d1|d2|1
......................................
Thanks
===
Here is my code
Quote:
grep "|" fileA.txt | sort -t"|" +0 -1 +2 -3 +5 -6 |
awk -F"|" '{
ani=$1;
betime=$2;
if ((ani != ani0) && (betime != betime0)) {
any0 = ani;
betime0 = betime;
date=$2;
entime=$3;
D1=$4
D2=$5;
diff=$6;
count = "0";
if ( diff <= 600 ) {
count = count + 1;
printf "%s,%s,%s,%s,%s,%s\n",ani,betime,entime,D1,D2,count >> output.txt
}
}
}'
but my asnswer is
3045678934,10:25,10:28,x1,x2,1
3045678934,10:28,10:31,z1,z2,1
4159061234,10:00,10:01,a1,a2,1
4159061234,10:05,10:06,c1,c2,1
4159061234,10:12,10:15,d1,d2,1