• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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


0
shahrahulb
Asked:
shahrahulb
  • 6
  • 5
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
ozoCommented:
#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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now