How do I specify tab as field separator for sort? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How do I specify tab as field separator for sort?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-26-2005
SSteve's Avatar
SSteve SSteve is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 9 March 2008, 10:22 PM EDT
Location: Sierra Foothills, California
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
How do I specify tab as field separator for sort?

I'm trying to use sort on a file with tab-delimited fields. I can't figure out how to tell sort to use the tab character as the field separator. I'm trying this on both an HP Unix system and on OS X (using bash on both).

Things I've tried:
sort -t\t
sort -t"\t"
sort -t\"\t\"

I've tried other things out of desperation, but nothing has worked so far.
I've looked through all the messages on the forum but couldn't find an answer. I found one message where someone was using the third form above, but that didn't work for me.

TIA,
-Steve
Sponsored Links
    #2  
Old 04-26-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 30 October 2014, 6:24 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
sort -t `/bin/echo '\t'`
Sponsored Links
    #3  
Old 04-26-2005
SSteve's Avatar
SSteve SSteve is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 9 March 2008, 10:22 PM EDT
Location: Sierra Foothills, California
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the quick reply, but that doesn't seem to work. Here's a sample input file where I've converted the tabs to vertical bars:

a album|c song|2
b album|d song|2
a album|a song|4
a album|b song|1
b album|z song|1
b album|a song|3
a album|f song|3
b album|c song|4

(The real file is an exported playlist from iTunes. This is a simplified test version.) I want to sort by album, then track number. With this file, sort -t\| -k 1,1 -k 3,3n works fine. But with the real file that contains tabs, nothing works. I tried sort -t `/bin/echo '\t'` -k 1,1 -k 3,3n but it sorts by the entire line just like everything else I've tried.
    #4  
Old 04-26-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 30 October 2014, 6:24 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
sort -t "`/bin/echo '\t'" -k 1,1 -k 3,3n
Sponsored Links
    #5  
Old 04-26-2005
SSteve's Avatar
SSteve SSteve is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 9 March 2008, 10:22 PM EDT
Location: Sierra Foothills, California
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks but still no luck. On OS X that still sorts by the entire line. On the HP system, it's rejected as invalid syntax. (I removed the character after the opening double quote since that must be a typo.)
Sponsored Links
    #6  
Old 04-26-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 30 October 2014, 6:24 PM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
sorry for the typo!

does this sort by the first field?
sort -t "`/bin/echo '\t'`" -k 1,1
Sponsored Links
    #7  
Old 04-26-2005
SSteve's Avatar
SSteve SSteve is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 9 March 2008, 10:22 PM EDT
Location: Sierra Foothills, California
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, "`/bin/echo '\t'`" did it! Thanks very much for your help and perseverance.

I'm not familiar with the "backwards" single quote. What does that do? (And what do you call it?)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Field separator X'1F' rohan10k Shell Programming and Scripting 2 05-24-2011 09:17 AM
field separator in awk yifangt Shell Programming and Scripting 11 01-30-2011 09:54 AM
awk, comma as field separator and text inside double quotes as a field. kevintse Shell Programming and Scripting 8 11-15-2010 05:31 PM
awk (nawk) field separator gc_sw Shell Programming and Scripting 4 11-03-2010 04:13 AM
Field separator in awk aoussenko Shell Programming and Scripting 2 03-29-2010 12:59 PM



All times are GMT -4. The time now is 12:51 AM.