Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-18-2011, 10:50 PM   #1
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:



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
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
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"...

Old 02-19-2011, 11:12 AM   #3
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.


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 > Forums > Linux Forums > Linux - Newbie

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

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