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

replace

i have a file temp.txt which has a line
ENVELOPE = "hkdscj@ljld.com";

in my perl script;send-multi.pl
my $user = "rshah1\@yahoo.com";
`perl -i -wpe 's/ENVELOPE = ".*"/ENVELOPE = "$user"/g' send-multi.pl`;


i want to replace hkdscj@ljld.com with rshah1\@yahoo.com
0
shahrahulb
Asked:
shahrahulb
  • 7
  • 5
  • 2
  • +1
1 Solution
 
ozoCommented:
my $user = "rshah1\@yahoo.com";
{local @ARGV=("temp.txt"); local $^I='';
  while( <> ){
     s/ENVELOPE = ".*?"/ENVELOPE = "$user"/g;
     print;
  }
}
0
 
shahrahulbAuthor Commented:
not working
0
 
TintinCommented:
or just run from the command line:

perl -i -pe 's/ENVELOPE = ".*?"/ENVELOPE = "rshah1\@yahoo.com"/g' temp.txt



0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ozoCommented:
Is
ENVELOPE = "hkdscj@ljld.com";
The exact line in temp.txt?
Could those spaces be tabs?
s/(ENVELOPE\s*=\s*)".*?"/$1"rshah1\@yahoo.com"/g
0
 
manav_mathurCommented:
>`perl -i -wpe 's/ENVELOPE = ".*"/ENVELOPE = "$user"/g' send-multi.pl`;

Do you want to change the entry in temp.txt or send-multi.pl??

0
 
shahrahulbAuthor Commented:
in send-multi.pl

in my perl script;send-multi.pl
my $user = "rshah1\@yahoo.com";
`perl -i -wpe 's/ENVELOPE = ".*"/ENVELOPE = "$user"/g' send-multi.pl`;

this is not working
0
 
manav_mathurCommented:
you say that ENVELOPE line is contained in temp.txt?? or is it in send-multi.pl??

Apologies, but im getting slightly confused by what you require

Manav
0
 
shahrahulbAuthor Commented:
i m really sorry, its my fault.

my script temp.pl has the following 2 statements
my $user = "rshah1\@yahoo.com";
`perl -i -wpe 's/ENVELOPE = ".*"/ENVELOPE = "$user"/g' send-multi.pl`;

and envelope is in send-multi.pl

0
 
manav_mathurCommented:
Are you running this on a Windows or a Unix OS??
0
 
shahrahulbAuthor Commented:
unix
0
 
manav_mathurCommented:
Try this

my $user = 'rshah1@yahoo.com';
`perl -i -wpe 's/ENVELOPE = ".*"/ENVELOPE = "\Q$user\E"/g' send-multi.pl`;
0
 
shahrahulbAuthor Commented:
awesome!!!!!!!!!!!!!!!
0
 
shahrahulbAuthor Commented:
what does \Q and \E do
0
 
manav_mathurCommented:
They will quote all metacharacters occuring between the \Q and the \E

0
 
shahrahulbAuthor Commented:
thx :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now