LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2005, 11:49 PM   #1
vimal480
LQ Newbie
 
Registered: Aug 2003
Posts: 4

Rep: Reputation: 0
Count of two columns


Hello Friends,

I have tab delimited big text file (700-800 MB file size). File format is

New york 101
NJ 102
Neww York 102
NJ 101
AZ 105
AZ 105
AZ 101
New york 101
NJ 102
NJ 102

I want count of coumn 1 and count 2. Output like

2 New York 101
1 New York 102
1 NJ 101
3 NJ 102
1 AZ 101
2 AZ 105

I am using sort filename | uniq -c command but it is taking long time.

Thanks,
 
Old 04-16-2005, 02:25 AM   #2
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Code:
[/home/soumen/proj/perl] $ cat cnt.pl
#!/usr/bin/perl

my %arr;
my $bigfile = q(./in.txt);
open BF, "< $bigfile" or die "Could not open $bigfile : $!\n";
while (<BF>) {
        ++$arr{"$_"};
}
close BF;

while (my ($key, $cnt) = each %arr) {
        print "$cnt $key";
}
[/home/soumen/proj/perl] $ ./cnt.pl
1 AZ 101
1 NJ 101
2 AZ 105
1 New York 102
3 NJ 102
2 New york 101
[/home/soumen/proj/perl] $
HTH.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vi Columns Chaitanyayardi Linux - Software 5 05-12-2005 07:27 AM
columns to lines Luskacik Linux - General 2 08-31-2004 11:38 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 06:47 PM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM
How can I see the other 10 columns sakulagi Linux - Software 1 06-16-2003 09:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration