![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 4 | 03-28-2009 04:10 PM |
| Count not correct | popeye | Shell Programming and Scripting | 3 | 04-22-2008 01:50 PM |
| How to count the record count in an EBCDIC file. | oracle8 | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 08:22 PM |
| CPU count | hshapiro | UNIX for Dummies Questions & Answers | 2 | 04-03-2006 02:08 PM |
| count fields | sskb | UNIX for Dummies Questions & Answers | 4 | 12-07-2001 12:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Count help - newbie
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:
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 Last edited by britney; 03-17-2006 at 08:16 PM.. |
|
|||||
|
Suggest you first read the rules about bumping your post - this will not get you a quicker response.
|
|
||||
|
Quick and dirty solution if the file isn't too big: Code:
IFS='|' while read a b do print $a"|$b"'|'$(grep -c ^$a z.dat) done < z.dat Sets the field separator to the pipe character then for each line print the original plus count of matches on the first field. Pro - simple, and no need for variables to hold counts or to sort the input, Anti - a grep for each line instead of for each unique value. You pays your money and takes your choice .cheers |
|
||||
|
The code you have gave me this answer
4159061234|10:00|10:01|a1|a2|60|4 4159061234|10:00|10:06|b1|b2|360|4 4159061234|10:05|10:06|c1|c2|60|4 4159061234|10:12|10:15|d1|d2|180|4 3045678934|10:25|10:28|x1|x2|180|3 3045678934|10:25|10:30|y1|y2|300|3 3045678934|10:28|10:31|z1|z2|180|3 It is not what I expected to get. Thanks, |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|