Convert AWK regex to Python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon May 16 07:29:15 EDT 2011


On Mon, 16 May 2011 03:57:49 -0700, J wrote:

> Most of the fields are separated by
> spaces except for couple of them which I am processing with AWK
> (removing "<G_" from the string for example).  So in essence what I want
> to do is evaluate each line in the log file and break them down into
> fields which I can call individually and write them to a new log file
> (for example selecting only fields 1, 2 and 3).

fields = line.split(' ')
output.write(fields[1] + ' ')
output.write(fields[2] + ' ')
output.write(fields[3] + '\n')



-- 
Steven



More information about the Python-list mailing list