Monday, May 29, 2006

To find out Unique lines in a file in Unix

The problem came to me like this.
The content of a file(a.txt):

1001 Moron
1002 Michel
1003 Adam
1004 Harry
1001 Moron
1006 Madhu
1001 Moron
1002 Michael


The question was to create a new file on the basis of unique values on first column.
The idea to do that is:
>Sort the file by the first column
>Then find out unique columns.

So the solution is:
sort -n a.txt|uniq -c > b.txt
b.txt will be the intended file.

Labels:

0 Comments:

Post a Comment

<< Home