LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-18-2011, 10:50 PM   #1
bibiki
LQ Newbie
 
Registered: Jul 2010
Posts: 19

Rep: Reputation: 0
using sort and uniq in bash


I have this file with the first lines as follows:



a
a

ability
able
abortions
about
about

say the file is named file1.txt

After i do the following:

sort file1.txt | uniq >> file2.txt

I expect that letter a would only appear once, not in two rows, word about would also appear only once. However, I can't seem to get that result using this. I also tried the sort -f file1.txt | uniq >> file2.txt but to no avail. I actually got file1.txt from a messier file using the -f option in sort command. Any help would be greatly appreciated.

Thank you.
 
Old 02-19-2011, 01:07 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Have you checked whether the lines w/ "a" have a different number
of spaces after the "a"?

Have a look w/ vim, use the command ":set list"...



Cheers,
Tink
 
Old 02-19-2011, 11:12 AM   #3
bibiki
LQ Newbie
 
Registered: Jul 2010
Posts: 19

Original Poster
Rep: Reputation: 0
I have checked whether the first two lines contain spaces after letter a, and found out that they do not. however, I think I found the solution.

My actual file had two empty lines in the beginning. Once I deleted the first two empty lines, I retried the command:

sort file1| uniq >> file2

and reached the desired result. thank you for your reply.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
history |tr '\011' ' ' |tr -s " "| cut -d' ' -f3 |sort |uniq -c |sort -nbr |head -n10 alan_ri General 12 12-04-2010 10:01 PM
[SOLVED] bash - merging strings (perhaps with sort | uniq) cmbouchard Linux - Newbie 4 11-17-2010 12:21 AM
bash sort problem ArthurHuang Programming 4 05-02-2009 06:20 PM
bash regex - sort czezz Programming 3 02-05-2009 08:41 PM
sort & uniq tostay2003 Programming 3 06-28-2008 07:14 PM


All times are GMT -5. The time now is 02:12 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration