[Wellington-pm] lookahead/behind in regex
Richard Hector
richard at walnut.gen.nz
Mon Oct 11 22:23:08 CDT 2004
Hi all,
Following Grant's talk last night, I'm getting a bit more
ambitious :-)
given a file, nagios.log, looking something like this:
[1097532863] SERVICE ALERT: ...blah...
[1097532863] SERVICE ALERT: ...blah...
[1097532913] SERVICE ALERT: ...blah...
[1097533037] SERVICE ALERT: ...blah...
[1097533093] SERVICE ALERT: ...blah...
[1097533107] SERVICE ALERT: ...blah...
I want the timestamps to be readable.
This works:
perl -p -e 's/^\[(\d+)\]/"[".localtime($1)."]"/e' < nagios.log
but this doesn't:
perl -p -e 's/^(?<=\[)(\d+)(?=\])/localtime($1)/e' < nagios.log
I wondered if the lookbehind and lookahead were saving their matches in
$1 and $3, but changing the $1 to $2 still doesn't work.
Any ideas?
Richard
More information about the Wellington-pm
mailing list