I want to replace all occurrences of a particular, previously-determined (known) email address --- with another email address, inside a PHP file; no regex should be involved ; sed
is the simplest way I know to do so.
This worked (the email has been changed):
sed -i 's/\$to = "[email protected]"/\$to = "example_1@example_1.com"/g' FILE
But I think it's generally wrong to do text processing with one liners especially if one finds them "too long", so I tried to break it to the following which doesn't work:
sed -i \
' \
-e s/
-e \$to = "[email protected]"/
-e \$to = "example_1@example_1.com"/
-e g
' \
FILE
sed: -e expression #1, char 8: unterminated address regex
How to break sed commands to nested parts when no regex and variable expansions are applied?
(i.e. when no regex and variable expansions / special quoting rules are part of the operation)
\$to = "[email protected]"
is a regular expression, even if it is only a very simple one. Thes//
operator matches on regular expressions, not fixed strings, even if they look kind of like fixed strings. 2. you can't do this with sed, but perl has/x
and/xx
regex modifiers to allow using whitespace (and comments) to make regular expressions more readable. Seeman perlre
and search for "Details on some modifiers".sed
commands.