[nzlug] A little help with some find and replace?

Nevyn nevynh at gmail.com
Sat Mar 29 01:00:25 NZST 2008


Is this strictly perl? I had thought sed myself.

On Fri, Mar 28, 2008 at 7:36 PM, Cliff Pratt <enkidu at cliffp.com> wrote:
> What's unreadable about "s/\[(\w+) (.*)\]/[\1 \L\2\E]/g"??
>
>  Cheers,
>
>  Cliff
>
>
>
>  Greg Fawcett wrote:
>  > I think I win on readability, but I have to submit to you on conciseness.
>  >
>  > On 28/03/2008, Simon Green <simon at simongreen.net> wrote:
>  >> On 28/03/2008, Greg Fawcett <greg at vig.co.nz> wrote:
>  >>> 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.
>  >> You know you've been using Perl too long when
>  >>
>  >> s/\[(\w+) (.*)\]/[\1 \L\2\E]/g
>  >>
>  >> makes more sense that you python code. :P
>  >>
>
>
>
>
> _______________________________________________
>  NZLUG mailing list NZLUG at linux.net.nz
>  http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
>



More information about the NZLUG mailing list