I have a PHP file which contains an email address as with
$to = "example-1_2@example-1_2.com"; and I want to replace the email address to another directly from the terminal.
The following code based on another similar code by Kuslanada worked:
read new_email_address sed -i 's/$to = ".*";$/$to = "'"$new_email_address"'";/' FILE
Kuslananda told me in comments (paraphrasing):
- My expression is the concatenation of a single-quoted string, a double-quoted string (the variable), and then another short single-quoted string
As a non professional sysadmin I might use
sed once in two years and I find its syntax somewhat difficult to remember and confusing for someone like me which doesn't work with it on a regular basis (the quoting rules clued by Kuslananda there are a bit confusing for me, let along when entire
sed commands are normally single-quoted by themselves).
Perhaps there is a way to make Kusalananda's command more "intuitive" or "accessible" for some others and myself. Maybe some backslashes to break the command to pieces would help or maybe another utility would be better for me to do such text replacement.
How to replace an email in a (PHP) file from the command line without