Kinda sorty

I needed a tool to perform relatively simple sorting. An output from ‘du -h’ looks like this:

~/ du -a -h cups-pdf
216K cups-pdf/job_41-_stdin_.pdf
2,6M cups-pdf/job_46-202aw__Polska_do_Droga_bez_nazwy_-_Mapy_Google.pdf
424K cups-pdf/job_45-274e_-_Lifestyle_-_studente.pdf
68K cups-pdf/job_44-Google_Maps_API_-_API_Key_Signup.pdf
40K cups-pdf/job_50-Wersja_do_druku___MICKIEWICZA_-_rondo.pdf
136K cups-pdf/job_58-Studia_magisterskie_-_program_po_zmianach_w_roku_2005.pdf
536K cups-pdf/job_40-_stdin_.pdf
1,6M cups-pdf/job_39-_stdin_.pdf
40K cups-pdf/job_52-263j.pdf
104K cups-pdf/job_43-cracking_wpa__Aircrack-ng_.pdf
34M cups-pdf/job_60-DjVu_PostScript_document.pdf
80K cups-pdf/job_56-Bluetooth_GPRS_Howto_-_ArchWiki.pdf
40K cups-pdf/job_51-Wersja_do_druku___Al_Podwale-Palisadowa.pdf
1,1M cups-pdf/job_42-_stdin_.pdf
41M cups-pdf

I needed it sorted per filesize, which is present in first column. Unfortunately I couldn’t find a way to do this with “sort” utility. So I wrote this tool. It works as it should:

█▓▒░tener@laptener░▒▓██▓▒░ śro gru 02 01:16:12
~/ du -a -h cups-pdf | sorty

40K cups-pdf/job_50-Wersja_do_druku___MICKIEWICZA_-_rondo.pdf
40K cups-pdf/job_52-263j.pdf
40K cups-pdf/job_51-Wersja_do_druku___Al_Podwale-Palisadowa.pdf
68K cups-pdf/job_44-Google_Maps_API_-_API_Key_Signup.pdf
80K cups-pdf/job_56-Bluetooth_GPRS_Howto_-_ArchWiki.pdf
104K cups-pdf/job_43-cracking_wpa__Aircrack-ng_.pdf
136K cups-pdf/job_58-Studia_magisterskie_-_program_po_zmianach_w_roku_2005.pdf
216K cups-pdf/job_41-_stdin_.pdf
424K cups-pdf/job_45-274e_-_Lifestyle_-_studente.pdf
536K cups-pdf/job_40-_stdin_.pdf
1,6M cups-pdf/job_39-_stdin_.pdf
1,1M cups-pdf/job_42-_stdin_.pdf
2,6M cups-pdf/job_46-202aw__Polska_do_Droga_bez_nazwy_-_Mapy_Google.pdf
34M cups-pdf/job_60-DjVu_PostScript_document.pdf
41M cups-pdf

I’ve put it on Hackage here, and the repo is on GitHub here.

Advertisements

~ by Tener on 01/12/2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: