Here is the code snipet I have that works, except for one thing...
CMD="perl -p -i -n -e "'"s/^5(.{68})$EFF_DATE/5\$1|$REP_DATE/g"'"
$FILE"
eval $CMD
I don't want that "|" character, but I need something to separate the
$1 for the perl group and the $REP_DATE from the ksh. The $REP_DATE
gets replaced in ksh with the string 080407 for instance, so how does
one separate the $1 group from the string 080407?
Does writing $1 as ${1} do it?
But you are essentially replacing $1 with itself! That seems
gratuitous to me. The stuff before $EFF_DATE is just context and
should not participate in the replacement operation. Why not an
expression something more like:
s/(?<=^5.{68})$EFF_DATE/$REP_DATE/
The /g should not be necessary, you only want one replacement per
line anyway.
I can't figure you would need both the -p and -n switches.
I tried the second suggestion and it didn't actually replace
anything... but doesn't that syntax remove the first 69 characters
from the actual string? Yes, I'm a perl rookie btw.
Another way to do it:
/^5/ && substr( $_, 69 ) =~ s/^$EFF_DATE/$REP_DATE/
> The /g should not be necessary, you only want one replacement per
> line anyway.
>
> I can't figure you would need both the -p and -n switches.
From perlrun.pod under the '-p' entry: "A -p overrides a -n switch." so
the -n switch in the OP's example is superfuous.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Heh, I didn't even look at what the switches meant... am editing
someone else's code and trying to improve on effeciency... it's a slow
script
If you can somehow arrange to run perl once, instead of lots of times,
you'll likely make it a good bit faster (assuming this perl invocation
is the bottleneck). Rewriting entirely in Perl is of course one way to
achieve this :).
Ben