0

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)

2
  • 1
    1. \$to = "[email protected]" is a regular expression, even if it is only a very simple one. The s// 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. See man perlre and search for "Details on some modifiers".
    – cas
    Commented Mar 28, 2021 at 5:18
  • See unix.stackexchange.com/questions/146955/… for a number of ways of splitting long sed commands.
    – fpmurphy
    Commented Mar 28, 2021 at 5:31

1 Answer 1

0

Try the following:

sed -i \
's/'\
'\$to = "[email protected]"'\
'/'\
'\$to = "[email protected]"'\
'/g'\
 FILE

Note the single space before FILE

0

Not the answer you're looking for? Browse other questions tagged .