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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-31-2008, 11:37 PM
|
#1
|
|
LQ Newbie
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3
Rep:
|
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?
|
|
|
|
02-01-2008, 12:27 AM
|
#2
|
|
LQ Newbie
Registered: May 2007
Posts: 7
Rep:
|
Hello,
I think you should just use sort :
Code:
$ echo 'Zeta
Apple
Bear
Gum
Apple
Gum
Tiger
Beargum' | sort -u
|
|
|
|
02-01-2008, 12:37 AM
|
#3
|
|
LQ Newbie
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3
Original Poster
Rep:
|
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.
|
|
|
|
02-01-2008, 03:03 AM
|
#4
|
|
Member
Registered: Nov 2005
Location: Philippines
Distribution: rhel, centos, opensuse, debian, ubuntu
Posts: 117
Rep:
|
On a command line.. you can invoke perl one-line command..
try this: perl -ane 'print unless $seen{$F[0]}++' testfile
|
|
|
|
02-01-2008, 03:39 AM
|
#5
|
|
LQ Newbie
Registered: Jan 2008
Location: India
Distribution: RHEL
Posts: 3
Original Poster
Rep:
|
Thanks a lot!! Works like a charm... [  ]
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:09 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|