sort based on criteria list

sort based on criteria list

Post by Eric Gorel » Wed, 13 Jan 1999 04:00:00



Is there a way within UNIX to sort a list based on specified criteria?
For
example, lets say I have a list of files:

mpp.opd
mpp.pef
mpp.fro
mpp.lsy

The extensions will always be one of the four listed (although the first

part may vary). I would like to sort the list based on the priority of
the
extension; pef 1st, opd 2nd, lsy 3rd and fro 4th. Is this possible?
Thanks
in advance for any help!

 
 
 

sort based on criteria list

Post by brian hile » Thu, 14 Jan 1999 04:00:00



> Is there a way within UNIX to sort a list based on specified criteria?
> For
> example, lets say I have a list of files:
> mpp.opd
> mpp.pef
> mpp.fro
> mpp.lsy
> The extensions will always be one of the four listed (although the first
> part may vary). I would like to sort the list based on the priority of
> the extension; pef 1st, opd 2nd, lsy 3rd and fro 4th. Is this possible?
> Thanks in advance for any help!

I can think of only one way to do so, which is very complicated indeed and
involved making a customized locale--not worth the effort.

A simpler method is, since you are dealing with files, is to create links
(either hard of soft) to the files, which themselves have the specified
lexigraphical order. (No, you are not using up any significant HD space.)

ln mpp.pef mpp.1st
ln mpp.opd mpp.2nd
ln mpp.lsy mpp.3rd
ln mpp.fro mpp.4th

And now use sort(1) or even better filename substitution, since
file globbing pre-sorts the expanded arguments:

echo mpp.[1-4]*

-Brian

 
 
 

sort based on criteria list

Post by Douglas Wils » Thu, 14 Jan 1999 04:00:00



>Is there a way within UNIX to sort a list based on specified criteria?
>For
>example, lets say I have a list of files:

>mpp.opd
>mpp.pef
>mpp.fro
>mpp.lsy

>The extensions will always be one of the four listed (although the first

sure, maybe something like:
ls -1 | awk '
/opd$/ { print "1:" $0 }
/pef$/ { print "2:" $0 }' | sort | cut -d: -f2

which should work as long as the filenames don't have a ':' in them.

Cheers,
Douglas Wilson

 
 
 

sort based on criteria list

Post by Charles Dem » Thu, 14 Jan 1999 04:00:00





>> Is there a way within UNIX to sort a list based on specified criteria?
>> For
>> example, lets say I have a list of files:
>> mpp.opd
>> mpp.pef
>> mpp.fro
>> mpp.lsy
>> The extensions will always be one of the four listed (although the first
>> part may vary). I would like to sort the list based on the priority of
>> the extension; pef 1st, opd 2nd, lsy 3rd and fro 4th. Is this possible?
>> Thanks in advance for any help!

>I can think of only one way to do so, which is very complicated indeed and
>involved making a customized locale--not worth the effort.

>A simpler method is, since you are dealing with files, is to create links
>(either hard of soft) to the files, which themselves have the specified
>lexigraphical order. (No, you are not using up any significant HD space.)

>ln mpp.pef mpp.1st
>ln mpp.opd mpp.2nd
>ln mpp.lsy mpp.3rd
>ln mpp.fro mpp.4th

>And now use sort(1) or even better filename substitution, since
>file globbing pre-sorts the expanded arguments:

>echo mpp.[1-4]*

>-Brian

I followed up to a different article with this solution (and some
other stuff), but thought I'd point it out here too.

As for the general question, you could write an awk script to
put a first field in front of the lines generated by the ls command,
then sort it based upon that field, and then strip the field with sed.

ls | awk -f addfield.awk | sort | sed -e 's/^[^ ][^ ]* //'

where addfield.awk is:

# Start of addfield.awk
/\.fro$/ {print "A",$0}
/\.lsy$/ {print "B",$0}
/\.opd$/ {print "C",$0}
/\.pef$/ {print "D",$0}
# End of addfield.awk

this script allows you to add a first field based upon the extension,
and putting in different letters (I used A B C D) will allow you to
control the sorting order.

The sed part strips out the first field.

I haven't tested this script out, but it should work.

Almost all things are possible in unix, btw, you just have to look at
them right, and combine the right tools.  :-)

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

sort based on criteria list

Post by Jack Tucke » Fri, 15 Jan 1999 04:00:00


: Is there a way within UNIX to sort a list based on specified criteria?
: For
: example, lets say I have a list of files:

: mpp.opd
: mpp.pef
: mpp.fro
: mpp.lsy

: The extensions will always be one of the four listed (although the first
: part may vary). I would like to sort the list based on the priority of
: the
: extension; pef 1st, opd 2nd, lsy 3rd and fro 4th. Is this possible?

In the strict context of the example given:

sort -t\. +1 -r file_list

Produces:

mpp.pef
mpp.opd
mpp.lsy
mpp.fro

Or have I missed something in the request?

Jack Tucker

 
 
 

1. sort based on list

Is there a way within UNIX to sort a list based on specified criteria? For
example, lets say I have a list of files:

mpp.opd
mpp.pef
mpp.fro
mpp.lsy

The extensions will always be one of the four listed (although the first
part may vary). I would like to sort the list based on the priority of the
extension; pef 1st, opd 2nd, lsy 3rd and fro 4th. Is this possible? Thanks
in advance for any help!

2. rsh hosta03 /home/vkgadm/applstart03.ksh does not end

3. Compare 2 sorted list , Print values present in list 1 only

4. how to define static routes

5. sort sort: 0653-657 A write error occurred while sorting (4.1.3)

6. can't boot from installer.coff

7. how to sort based on the file NAME size ???

8. Get Rid of MSh*t ^M's <CR> from a file...

9. sort keys based on character positions, not field positions?

10. how do I sort a file based on multiple columns

11. Web Based E-mail Sorting System Required

12. mail client for linux to sort incomming messages based on sender email?

13. Looking for Unix-based AWK that does Array sorting