Link to home
Start Free TrialLog in
Avatar of shahrahulb
shahrahulb

asked on

replace

i have a file application.txt

BillingLL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LL0

i want to replace that by

BillingLL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LL1

(replacing 0 by 1 at the end)

in my perl script, this is not working

`perl -i -wpe 's/Billing(.*)LL00LL0$/Billing($1)LL00LL1/g' applications.txt`;


Avatar of ozo
ozo
Flag of United States of America image

If Billing and LL00LL0 are on separate lines, you may need to change that to
perl -i -0777wpe 's/Billing(.*?)LL00LL0/Billing($1)LL00LL1/sg'

You might also want to verify whether the name of the file is
application.txt
or
applications.txt
Avatar of shahrahulb
shahrahulb

ASKER

`perl -i -0777wpe 's/Billing(.*?)LL00LL0/Billing($1)LL00LL1/sg' applications.txt`;

not working in perl script
let me give u my comple string in applications .txt

BillingLL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LLApr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00LL0d:00h:00mLL00LL0


after tring  `perl -i -0777wpe 's/Billing(.*?)LL00LL0/Billing($1)LL00LL1/sg' applications.txt`;

i get   Billing(Apr)LL00LL1LL00LLApr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00LL0d:00h:00mLL00LL0

Assuming that
BillingLL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LLApr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00LL0d:00h:00mLL00LL0
is all on one line, that the name of the file is
applications.txt
not
application.txt
and that there are no unseen whitespace characters between LL00LL0 and the end of the line,
perl -i -wpe 's/Billing(.*)LL00LL0$/Billing($1)LL00LL1/g' applications.txt
should have produced
Billing(LL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LLApr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00LL0d:00h:00m)LL00LL1

perl -i -wpe 's/Billing(.*)LL00LL0$/Billing$1LL00LL1/' applications.txt
would produce
BillingLL00LLOOS Not ActiveLL00LL        TESTING!!        ::::         TESTING!!         LL00LL1114271029LL00LL4LL00LL0LL00LLApr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00LL0d:00h:00mLL00LL1

If there are whitespace characters afer LL00LL0 which you want to keep, you then
perl -i -wpe 's/Billing(.*)LL00LL0(\s*)$/Billing$1LL00LL1$2/' applications.txt
would do it
i guess u have misunderstood me.

perl -i -wpe 's/Billing(.*)LL00LL0$/Billing($1)LL00LL1/g' applications.txt

works fine from command prompt

but not from perl script, because for perl $ is special character
when i execute my perl script i get error:
Substitution replacement not terminated at -e line 2.
if i try
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing$1LL00LL1/' applications.txt");


i get:
BillingLL00LL1

cannot get anything between Billing and LL00LL1
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
`perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing\$1LL00LL1/' applications.txt`;

This worked :-)

why do we have to do \$1   i m surprised
system(q"perl -i -wpe 's/Billing(.*)LL00LL0$/Billing$1LL00LL1/' applications.txt");
or
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing\$1LL00LL1/' applications.txt");
Without the \, $1 and $/ in `` or "" are interpolated immediately, so they are not seen by the -e