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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting and outputing only unique records based on first field

Status
Not open for further replies.

horse123

Technical User
Oct 13, 2003
17
0
0
AU
Hi I've got a file with about 20,000 records in the following lines (layout):

XXXXXXXXX||XXXXX|XXXXX

X means alpha-numeric chars

I want everything in XXXXXXXXX||, which is a kind of first(field),to be unique and output to a separate file.

I first did this with "sort file_name | uniq > new_file_name"
I believe this is an incorrect approach.

I then did this with "sort +0, -1, -u, -t "||" file_name > new_file_name"
I am still not convinced.
Is there any better approach? Thanks in advance
 
Try something like this:
Code:
sort -t "|" -k 1,1 file_name > new_file_name

Hope This Help
PH.
 
Hi, I've tried using the above command:
sort -t "|" -k 1,1 file_name > new_file_name

It results an output with same lines as the original file.

I wonder ...

but how to do with two pipes ||
 
I solved this problem by adding a -u , so

sort -t "|" -k 1,1 -u file_name > new_file_name

I got an output with the same lines as when I used the following:

"sort +0, -1, -u, -t "|" file_name > new_file_name"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top