sorting a file
Wojtek Walczak
gminick at hacker.pl
Thu Dec 5 11:57:16 EST 2002
Dnia 5 Dec 2002 08:08:16 -0800, Romualdo napisał(a):
> Does anybody could tell me how the lines above would look like in
> python?
It's not exactly what you want, but should be helpful.
Our file (~/plik):
---
/home/gminick/text /home/gminick/text.txt
/home/gminick/blah /home/gminick/blah.txt
---
Our script:
---
import re, os
w = open("plik")
a = w.readline()
while a:
b = re.search("([\w\/\.]+)\s+([\w\/\.]+)", a)
if b:
b = b.groups()
os.system("mv %s %s" % (b[0], b[1]))
a = w.readline()
---
It reads lines from file "plik" and searching for two path(/file)names,
if found it moves a file from a name found in first field, to that found
in second.
So, here we're moving two files: text to text.txt and blah to blah.txt.
HTH.
--
[ ] gminick (at) underground.org.pl http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]
More information about the Python-list
mailing list