LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sort Text by length. (http://www.linuxquestions.org/questions/linux-newbie-8/sort-text-by-length-699503/)

n0futur3 01-23-2009 09:35 PM

Sort Text by length.
 
Hi can anyone tell me how can i sort a text file by LENGTH ? I had a c++ script once , but i can't find it. Please someone tell me how.

JulianTosh 01-24-2009 05:58 AM

in python:
Code:

import sys
lines = sys.stdin.readlines()
lines.sort(lambda l1,l2: cmp(len(l1),len(l2)))
for l in lines:
  sys.stdout.write(l)



All times are GMT -5. The time now is 10:20 AM.