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`;


LVL 1
shahrahulbAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
#inside a perl script
`perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing\$1LL00LL1/' applications.txt`;
#or
{local @ARGV=('applications.txt'); local $^I='';
 while( <> ){
    s/Billing(.*)LL00LL0$/Billing$1LL00LL1/;
    print;
 }
}
0
 
ozoCommented:
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
0
 
shahrahulbAuthor Commented:
`perl -i -0777wpe 's/Billing(.*?)LL00LL0/Billing($1)LL00LL1/sg' applications.txt`;

not working in perl script
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
shahrahulbAuthor Commented:
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

0
 
ozoCommented:
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
0
 
shahrahulbAuthor Commented:
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
0
 
shahrahulbAuthor Commented:
when i execute my perl script i get error:
Substitution replacement not terminated at -e line 2.
0
 
shahrahulbAuthor Commented:
if i try
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing$1LL00LL1/' applications.txt");


i get:
BillingLL00LL1

cannot get anything between Billing and LL00LL1
0
 
shahrahulbAuthor Commented:
`perl -i -wpe 's/Billing(.*)LL00LL0\$/Billing\$1LL00LL1/' applications.txt`;

This worked :-)

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.