LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-23-2009, 09:35 PM   #1
n0futur3
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
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.
 
Old 01-24-2009, 05:58 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash read in variable length text records lynx81191 Programming 4 11-17-2007 09:53 PM
sed: delete text till <pattern2> depending on length of text oyarsamoh Programming 2 05-05-2007 02:40 AM
How to Increase Length of the Icon Text KimInWis Suse/Novell 5 12-04-2006 08:38 PM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 09:40 PM
storing text in a text file for a specified length of time. mrobertson Programming 7 08-02-2005 11:27 AM


All times are GMT -5. The time now is 03:31 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration