Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting phone numbers

Status
Not open for further replies.

YOUNGCODGER

Programmer
Jul 9, 2007
102
GB

Hello,

I have an extremely large text file with over 1 million lines. The data is in fixed positions and relates to phone calls. I need to find how many times each number was called. 'Cut -c' and sort and sort will give me the list of numbers but how do I get a total for each number?

Many thanks,

Youngcodger [bigglasses]
 
Hi

Wrong. You have to use [tt]cut[/tt] + [tt]sort[/tt] + [tt]uniq[/tt] to achieve that.
Code:
cut -c 6-14 /input/file | sort | uniq -c
Code:
awk '{n[substr($0,6,9)]++}END{for(i in n)print i,n[i]}' /input/file
( In my sample I had 9 character long phone numbers starting at position 6. )

Feherke.
 

Thanks Feherke! It gave me over 150,000 separate numbers and highlighted some nasty corruptions in the file.

Thanks again,

Young Codger [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top