[nzlug] A little help with some find and replace?
Greg Fawcett
greg at vig.co.nz
Fri Mar 28 10:04:16 NZST 2008
You could spend hours getting the regex right, or you could use a little
python magic...
inFile=file('input.txt','r')
outFile=file('output.txt','w')
lineCount=0
for line in inFile:
lineCount+=1
if line[0]=='[':
spacePos=line.find(' ')
if spacePos!=-1:
outFile.write(line[:spacePos]+line[spacePos:].lower())
else:
print "Line %d doesn't contain a space"%lineCount
else:
print "Line %d doesn't start with '['"%lineCount
inFile.close()
outFile.close()
This will convert infile.txt to outfile.txt, with some rudimentary error
checking.
Cheers!
Greg.
On 28/03/2008, Simon <greminn at gmail.com> wrote:
>
> Hi There,
>
> Just wondering if someone that is much better than me at regular
> expressions could give me a bit of a hand here?
>
> We have some websites (moving from Windows to Linux hosting platform)
> that have CAPITOL letters in the code (god forbid!) that need to be
> replaced. A possible line that needs to be changed is...
>
> [ListFiles ../Website/Orders/[current]/][hideif [filename]^icon]
>
> which needs to be changed to:
>
> [ListFiles ../website/orders/[current]/][hideif [filename]^icon]
>
> There is always a '[' then some text, which is directly after the "[".
> Esentially [CommandThatStaysAsItIs AllThisNeedsToBeChanged].
>
> Any ideas?
>
> Thanks!
>
> Simon
>
> _______________________________________________
> NZLUG mailing list NZLUG at linux.net.nz
> http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
>
--
Phone: +64 3 409 8165
Mobile: +64 21 333 291
Fax: +64 3 974 6810
Web: www.vig.co.nz
More information about the NZLUG
mailing list