I would like to substitute a substring that contains an @
character with Perl as in the following sed command:
substitution='[email protected]'
sed 's/[email protected]/'"${substitution}"'/g' <<< "The current e-mail address is [email protected]"
At present wherever I use Perl instead of sed or awk I first replace \
with \\
, /
with \/
, $
with \$
and @
with \@
; e.g.
substitution='[email protected]'
substitution="${substitution//\\/\\\\}"
substitution="${substitution//\//\\/}"
substitution="${substitution//$/\\$}"
substitution="${substitution//@/\\@}"
perl -pe 's/oldusername\@website.com/'"${substitution}"'/g' <<< "The current e-mail address is [email protected]"
I have read about using single quotation marks (as below based on sed/ perl with special characters (@)) but I was wondering if there is any other way to do this with forward slashes?
substitution='[email protected]'
perl -pe "s'[email protected]'"${substitution}"'g" <<< "The current e-mail address is [email protected]"
Also, are there special characters in Perl aside from $
, @
and %
(and why is there no need to escape %
)?