Im trying to use sed command in order to find an error in my text file and replace it with something else.
like i said before sed works perfectly for me without using double quotes in the text, also this -> ~ doesnt work like you suggested, unless i used it wrong. The Perl script
#!/usr/bin/perl
use strict;
use warnings;
my @array = (
"^OPTIONS.*\-X",
"^OPTIONS.*\-x"
);
my $Replace_To = 'OPTIONS="-u hello:bye -p /var/run/myfile.pid -g"'
chomp $Replace_To;
my strCommand;
my $array;
sub main
{
my $hostname = `hostname -s`;
chomp $hostname;
foreach $array(@array)
{
my $execute = `awk '/$array/' /tmp/file.txt
if($execute)
{
chomp $execute;
$strCommand = `sed -i 's/$execute/$Replace_To/g' /tmp/file.txt`;
}
}
}
&main();