Reputation: 33
I have a file with below content:
$ cat file
my name is PARESH.
Need to replace PARESH
with content of variable `$REPLACE_WORD" using Perl.
perl -pi -e "s/PARESH/$REPLACE_WORD/g" file
Problem is variable $REPLACE_WORD
has special characters in it.
$REPLACE_WORD="c@sc9ey"
Upvotes: 0
Views: 56
Reputation:
When using double quotes, then escape the special characters using \
$REPLACE_WORD = "c\@sc9ey";
Upvotes: 1
Reputation: 54333
Perl interpolates scalars ($foo
) and arrays (@bar
) in double quotes ""
. If you use single quotes ''
instead, no interpolation happens.
$REPLACE_WORDS = 'c@sc9ey';
Note that hash variabels (%baz
) are not interpolated.
Upvotes: 4