LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2009, 05:19 PM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
sort ignoring articles


is there a smart way to sort things ignoring articles (a, an, the). basically i would want:
Code:
[schneidz@hyper schneidz]$ ls -1 /media
smokin-aces.avi
so-close.avi
spy-game.avi
street-fighter-alpha-2001.avi
talladaga-nights.avi
the-departed.avi
the-happening.avi
transformers.avi
vantage-point.avi
to sort like:
Code:
[schneidz@hyper schneidz]$ ls -1 /media
the-departed.avi
the-happening.avi
smokin-aces.avi
so-close.avi
spy-game.avi
street-fighter-alpha-2001.avi
talladaga-nights.avi
transformers.avi
vantage-point.avi
thanks,
 
Old 04-27-2009, 05:47 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by schneidz View Post
is there a smart way to sort things ignoring articles (a, an, the). basically i would want:
Code:
[schneidz@hyper schneidz]$ ls -1 /media
smokin-aces.avi
so-close.avi
spy-game.avi
street-fighter-alpha-2001.avi
talladaga-nights.avi
the-departed.avi
the-happening.avi
transformers.avi
vantage-point.avi
to sort like:
Code:
[schneidz@hyper schneidz]$ ls -1 /media
the-departed.avi
the-happening.avi
smokin-aces.avi
so-close.avi
spy-game.avi
street-fighter-alpha-2001.avi
talladaga-nights.avi
transformers.avi
vantage-point.avi
thanks,
You'll need an external script to pipe 'ls' output into.
 
Old 04-27-2009, 05:51 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
ls | sed -e 's/^.*$/& &/;s/^the-//;s/^an-//;s/^a-//' | sort -k1 | sed 's/^.* //'
Note #1: Only ignores articles that are the first word.
Note #2: Only works if '-' is used to seperate words.

Last edited by Hko; 04-27-2009 at 05:53 PM.
 
1 members found this post helpful.
  


Reply



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
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
php sort help - sort numerical descending then by alphabetical? RavenLX Programming 3 03-11-2009 08:35 AM
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 07:44 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 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