Friday, July 07, 2006

To find out Unique lines in a file in Unix---Continuation

I had one post in my blog on Unique.And the solution was also there.This time I got a file ( say gg.txt ) contents like :

5570, 5570, 5570, 5570, 5570, 5578, 5594, 5570, 5570, 5585, 5570, 5570, 5570, 5570, 5570, 5570, 5585, 5570, 5570, 5570, 5570, 5570, 5570, 5570, 5585, 5570, 5570, 5585, 5570, 5585, 5570, 5570, 5570, 5585, 5570, 5570, 5585, 5570, 5570, 5585, 5570, 5570, 5570,


They are as different rows in the original file.I was to find out uniq records from them.When i ran:

$ sort -n gg.txt|uniq -c > hh.txt

The hh.txt file becomes like:


1 1220,
2 4273,
1 4582,
4 4683,
1 4790,
1 4933,
1 5043,
1 5086,
1 5214,
6 5363,
3 5390,
2 5396,
2 5460,
1 5462,
221 5476,
48 5477,
26 5478,
229 5479,
35 5480,
145 5481,
54 5482,
6 5483,
6409 5485,
52 5486,
29 5487,
12 5488,
2 5492,
1 5516,
7 5536,
48880 5570


The first column saying how many times that specific records occurred in the file gg.txt.

Although that migght be useful in cases,but I want the unique records only not their counts also as I am to build a SQL query on that output.So I ran this command

$ sort gg.txt|uniq > hhh.txt

And now the records become:

5476, 5477, 5478, 5479, 5480, 5481, 5482, 5483, 5485, 5486, 5487, 5488, 5570, 5578, 5585, 5594, 5598, 5599, 5605, 5608,

And thats wat I want.

Labels:

0 Comments:

Post a Comment

<< Home