LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2008, 11:37 PM   #1
adroit_91
LQ Newbie
 
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3

Rep: Reputation: 0
How to Uniquify w/o sorting??


Hello everyone.

I need to uniquify a file which contains only strings, but not in a sorted order. What I basically mean to achieve is that without touching the order of the contents, I should be able to do away with repetitions! Although i can easily write a PERL script for the same, I want to achieve the same through the linux prompt.

Eg:
A file containing the following:

Zeta
Apple
Bear
Gum
Apple
Gum
Tiger
Beargum


Should become:

Zeta
Apple
Bear
Gum
Tiger
Beargum



Is it possible through the command prompt?
 
Old 02-01-2008, 12:27 AM   #2
fargie_s
LQ Newbie
 
Registered: May 2007
Posts: 7

Rep: Reputation: 0
Hello,

I think you should just use sort :

Code:
$ echo 'Zeta
Apple
Bear
Gum
Apple
Gum
Tiger
Beargum' | sort -u
 
Old 02-01-2008, 12:37 AM   #3
adroit_91
LQ Newbie
 
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3

Original Poster
Rep: Reputation: 0
Not what I need

Sort -u will uniquify as well as sort, although, I do not want it sorted at all. I want simply the output uniquified, but the remaining content's order should be untouched!

Thanks anyway.
 
Old 02-01-2008, 03:03 AM   #4
yongitz
Member
 
Registered: Nov 2005
Location: Davao City, Philippines
Distribution: RHEL, CentOS, Ubuntu, Mint
Posts: 139

Rep: Reputation: 20
On a command line.. you can invoke perl one-line command..

try this: perl -ane 'print unless $seen{$F[0]}++' testfile
 
Old 02-01-2008, 03:39 AM   #5
adroit_91
LQ Newbie
 
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks a lot!! Works like a charm... []
 
  


Reply

Tags
file, list, sort



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting problem ltordsen Programming 2 11-02-2005 03:25 PM
Sorting data. unreal128 Linux - Software 1 09-20-2005 06:31 PM
Which sorting algorithm? nodger Programming 6 01-28-2005 06:13 PM
sorting and stuff arnulfo Programming 13 01-01-2005 04:37 PM
Sorting Beppe83 Linux - Software 7 06-21-2004 09:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration