Sort lines in a text file

James Stroud jstroud at mbi.ucla.edu
Mon Jul 23 03:56:05 EDT 2007


Daniel wrote:
> On Sun, 22 Jul 2007 06:03:17 +0300, leegold <goldtech at worldpost.com> wrote:
>> say I have a text file:
>>
>> zz3 uaa4a ss 7 uu
>>   zz 3 zzzz66 ppazz9
>> aaaaaaaaa00000zz0
>>
>> I want to sort the text file. I want the key to be the number after
>> the two "zz".  Or I guess a string of two zz then a number....So
>> that's 3, 9, 0
>>
>> I'm trying to say that I want to sort lines in a file based on a
>> regular expression. How could I do that in Python? I'm limited to
>> Python 2.1, I can't add any 2nd party newer tools.
>>
>> Thanks
>> Lee G.
>>
> 
> Shouldn't it be 3, 6, 9, 0

I'm guessing that the 6 comes after 4 z's and not 2 z's in line 2 so it 
is ignored.



More information about the Python-list mailing list