shahrahulb
asked on
replace
i have a file application.txt
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL 0
i want to replace that by
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL 1
(replacing 0 by 1 at the end)
in my perl script, this is not working
`perl -i -wpe 's/Billing(.*)LL00LL0$/Bil ling($1)LL 00LL1/g' applications.txt`;
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
i want to replace that by
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
(replacing 0 by 1 at the end)
in my perl script, this is not working
`perl -i -wpe 's/Billing(.*)LL00LL0$/Bil
ASKER
`perl -i -0777wpe 's/Billing(.*?)LL00LL0/Bil ling($1)LL 00LL1/sg' applications.txt`;
not working in perl script
not working in perl script
ASKER
let me give u my comple string in applications .txt
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL Apr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00 LL0d:00h:0 0mLL00LL0
after tring `perl -i -0777wpe 's/Billing(.*?)LL00LL0/Bil ling($1)LL 00LL1/sg' applications.txt`;
i get Billing(Apr)LL00LL1LL00LLA pr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00 LL0d:00h:0 0mLL00LL0
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
after tring `perl -i -0777wpe 's/Billing(.*?)LL00LL0/Bil
i get Billing(Apr)LL00LL1LL00LLA
Assuming that
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL Apr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00 LL0d:00h:0 0mLL00LL0
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$/Bil ling($1)LL 00LL1/g' applications.txt
should have produced
Billing(LL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL Apr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00 LL0d:00h:0 0m)LL00LL1
perl -i -wpe 's/Billing(.*)LL00LL0$/Bil ling$1LL00 LL1/' applications.txt
would produce
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0 0LL0LL00LL Apr 23 2005, 11:43:19LL00LLApr 23 2005, 11:43:49LL00LL0LL00LL0LL00 LL0d:00h:0 0mLL00LL1
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
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
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$/Bil
should have produced
Billing(LL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
perl -i -wpe 's/Billing(.*)LL00LL0$/Bil
would produce
BillingLL00LLOOS Not ActiveLL00LL TESTING!! :::: TESTING!! LL00LL1114271029LL00LL4LL0
If there are whitespace characters afer LL00LL0 which you want to keep, you then
perl -i -wpe 's/Billing(.*)LL00LL0(\s*)
would do it
ASKER
i guess u have misunderstood me.
perl -i -wpe 's/Billing(.*)LL00LL0$/Bil ling($1)LL 00LL1/g' applications.txt
works fine from command prompt
but not from perl script, because for perl $ is special character
perl -i -wpe 's/Billing(.*)LL00LL0$/Bil
works fine from command prompt
but not from perl script, because for perl $ is special character
ASKER
when i execute my perl script i get error:
Substitution replacement not terminated at -e line 2.
Substitution replacement not terminated at -e line 2.
ASKER
if i try
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Bi lling$1LL0 0LL1/' applications.txt");
i get:
BillingLL00LL1
cannot get anything between Billing and LL00LL1
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Bi
i get:
BillingLL00LL1
cannot get anything between Billing and LL00LL1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
`perl -i -wpe 's/Billing(.*)LL00LL0\$/Bi lling\$1LL 00LL1/' applications.txt`;
This worked :-)
why do we have to do \$1 i m surprised
This worked :-)
why do we have to do \$1 i m surprised
system(q"perl -i -wpe 's/Billing(.*)LL00LL0$/Bil ling$1LL00 LL1/' applications.txt");
or
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Bi lling\$1LL 00LL1/' applications.txt");
or
system("perl -i -wpe 's/Billing(.*)LL00LL0\$/Bi
Without the \, $1 and $/ in `` or "" are interpolated immediately, so they are not seen by the -e
perl -i -0777wpe 's/Billing(.*?)LL00LL0/Bil
You might also want to verify whether the name of the file is
application.txt
or
applications.txt