in reply to String Search/Replace
#!c:\perl\bin\perl.exe -w use strict; use warnings; for my $line (<DATA>) { $line =~ s/ \d{4,}( |$)/ 0$1/g; print $line; } __DATA__ 1125356700 0 0 0 0 1125356400 15 0 25 0 1125356100 25 0 25 0 1125355800 25 0 25 0 1125355500 25 0 25 0 1125397800 0 0 0 0 1125397500 0 0 0 0 1125397200 0 0 0 0 1125396900 0 0 0 0 1125396600 0 0 0 0 1125396300 0 0 0 0 1125396000 39006 0 63597 0 1125395700 63597 0 63597 0 1125395400 63597 0 63597 0 1125395100 63597 0 63597 0 1125394800 63597 0 63597 0 1125394500 63597 0 63597 0 1125394200 63597 0 63597 0
Or for a one liner:
perl.exe -ple "s/ \d{4,}( |$)/ 0$1/g" filename
Update:
Oops... As cheseter has pointed out, the above will replace 1000 when it should not.
Here's my regex that works:
or at least I think it does.$line =~ s/ (\d+)/$1>1000?" 0":" $1"/ge;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: String Search/Replace
by ikegami (Patriarch) on Aug 31, 2005 at 15:33 UTC | |
by ChrisR (Hermit) on Aug 31, 2005 at 15:49 UTC | |
by Roy Johnson (Monsignor) on Aug 31, 2005 at 16:10 UTC | |
|
Re^2: String Search/Replace
by chester (Hermit) on Aug 31, 2005 at 16:03 UTC | |
by ChrisR (Hermit) on Aug 31, 2005 at 17:50 UTC | |
|
Re^2: String Search/Replace
by gargle (Chaplain) on Aug 31, 2005 at 18:38 UTC |