From: unruh on 12 Jun 2010 21:08 On 2010-06-12, John Reiser <jreiserfl(a)comcast.net> wrote: >> abc >> def >> ghi >> abc >> jkl >> >> How do I remove the second (duplicate) "abc" wih >> a shell command? > > The shell command 'uniq' has been around for more than 30 years. > man uniq .... Note: 'uniq' does not detect repeated lines unless they are adja- cent. You may want to sort the input first, or use 'sort -u' with- out 'uniq'.
From: unruh on 12 Jun 2010 21:10 On 2010-06-12, Todd <todd(a)invalid.com> wrote: > On 06/11/2010 08:54 PM, unruh wrote: >> On 2010-06-12, Todd<todd(a)invalid.com> wrote: >>> Hi All, >>> >>> I have a file: >>> >>> abc >>> def >>> ghi >>> abc >>> jkl >>> >>> How do I remove the second (duplicate) "abc" wih >>> a shell command? >> >> sort -u? >> Although that will change the order of the lines. (well not in this >> case, but in general) >> >>> >>> May thanks, >>> -T > > $ cat eraseme.txt | sort -u > abc > def > ghi > jkl > > This I like. I typically want to both sort and remove > duplicates. And it is easy to understand too. Even better if you do sort -u eraseme.txt > > Thank you!, > -T
From: Todd on 13 Jun 2010 17:09 O>> $ cat eraseme.txt | sort -u >> abc >> def >> ghi >> jkl >> >> This I like. I typically want to both sort and remove >> duplicates. And it is easy to understand too. > > Even better if you do > sort -u eraseme.txt My final script line. Thank you all for the help! -T EchoStatus "status" "`su $DefaultUser -c "/usr/bin/VBoxManage list runningvms | grep -e "{" " | sort -u`"
From: Rahul on 15 Jun 2010 13:00 Todd <todd(a)invalid.com> wrote in news:huv0hu$q2a$1(a)speranza.aioe.org: > $ cat eraseme.txt | awk '!x[$0]++' > abc > def > ghi > jkl > Obviously, you have the nicer solution. But before today here's how I used to do it: cat eraseme.txt | nl | sort -k2 | uniq -f1 | sort -k1 | cut -f2 It's clunky but has worked for me. Of course, now I'll switch to your awk snippet. :) -- Rahul
First
|
Prev
|
Pages: 1 2 3 Prev: GoogleEarth and CentOS glibc problem Next: 2010 FIFA World Cup Brazil football jersey |