how to 'sort' by file extension then alphabetical order
Hi helpful people, i have a text file that lists hundreds of files, one per line. e.g:
ccc.avi bbb.doc bbb.avi bbb.mp3 ccc.doc aaa.mp3 How can i sort this file, firstly by extension type, and for each group of matching extensions, into alphabetical order? e.g: bbb.avi ccc.avi bbb.doc ccc.doc aaa.mp3 bbb.mp3 cheers :-) |
It's a good idea to check the man page before posting. For example, man ls lists the -X switch:
Code:
~/tmp$ ls -l |
Please see the "man sort" manpage. If you make the decimal point the field separator, and sort by the second field, you will get the results you want.
This will work for 8.3 filenames, or other filenames that contain only one decimal point in the name. Your locale setting can effect how things are sorted. For some locale settings 'a'=='A'. For others 'a' < 'A'. The locale settings can also effect grep and sed. I discovered this when [[:lower:]] was selecting upper case letters in a regular expression. By the way, there is also a "man regex" man page. |
thank you :-)
thanks to the both of you. I will be sure and check the man pages more carefully next time. :-)
|
They were right...
using the below 'sort' options as i think i now understand them (thanks helpers), the -t (something) allows one to designate what string will be used to seperate a larger string into fields either side of it. The --key=2 translates to 'use the field following the separator string to sort by'. So;
sort -t . --key=2 worked ok. Noted only when file follow the blarty.bla format and not bar.ty.bla |
All times are GMT -5. The time now is 12:00 PM. |