![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix File operations | nivas | Shell Programming and Scripting | 14 | 02-11-2008 01:27 AM |
| Unix file operations(shell script) | nivas | Shell Programming and Scripting | 6 | 02-07-2008 03:11 AM |
| command for a series of operations | phiber_optik | Shell Programming and Scripting | 1 | 12-21-2007 02:57 AM |
| String Operations | Rohini Vijay | Shell Programming and Scripting | 9 | 04-21-2006 08:32 AM |
| File operations | chiragmistry21 | Shell Programming and Scripting | 2 | 03-27-2006 02:00 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi
I have a tab delimited file with 3 fields. I need to sort this file on the first field and remove all the records where the first field has dulplicates. For eg my file is 133|arrfdfdg|sdfdsg 234|asfsdgfs|aasdfs 133|affbfsde|dgfg When this file gets sorted I need the result to be 234|asfsdgfs|aasdfs So if there are duplicate entries in the first column, all those records should be removed. How can I do this in unix? I am able to sort it to get single records based on unique first field using sort -u -k 1,1 filename but this is not what I am looking for. Any help will be appreciated! |
| Forum Sponsor | ||
|
|
|
|||
|
To just print non-repeated lines in the file turns out to be a bit of a pain. The uniq command would do it but only if the key is on the right hand side of the line, so I've put it there.
The code sorts the file on the first column (delimited by pipes) then appends the key to the end of the line uses and uses uniq to remove line with non-repeated keys before stripping off the added key! Looks a bit klunky - I'm sure that someone could do something more elegant Code:
Code
sort -t'|' -k1,1 < yourfile.txt | while read x
do
print $x ${x%%'|'*}
done | uniq -f1 -u | cut -d' ' -f1
|
|||
| Google The UNIX and Linux Forums |