You seem to be saying
that you want to replace the string that appears after the =
,
no matter what it is —
for example, in the sample data,
you want to replace Lnreddy37@gmail.com
.
But you’re saying that, no matter what the string after the =
is,
you want to replace it with reddy17777@gmail.com
—
apparently you want that hardcoded.
There are a few variations on how to do this.
The simplest is
sed 's/RESOURCE=.*/RESOURCE=reddy17777@gmail.com/'
which (like all the below commands)
uses the fact that .*
means “match whatever is there”.
If you don’t want to type RESOURCE=
twice, you can shorten the above to
sed 's/\(RESOURCE=\).*/\1reddy17777@gmail.com/'
where \(
…\)
marks a part of the search string as a group
(you can have up to nine groups) and \1
means replace with the first group.
The above commands will find and replace RESOURCE=
wherever it appears on the line.
So, for example, the input
# Lakshminarayana wants to change all occurrences of "RESOURCE=".
RESOURCE=john@yahoo.com
COORDINATOR=paul@hotmail.com
MUSIC_RESOURCE=nasir37@yahoo.com
FOX RESOURCE=The quick brown fox
# Comment: Originally line 2 said RESOURCE=ringo@liverpool.co.uk
would be changed to
# Lakshminarayana wants to change all occurrences of "RESOURCE=reddy17777@gmail.com
RESOURCE=reddy17777@gmail.com
COORDINATOR=paul@hotmail.com
MUSIC_RESOURCE=reddy17777@gmail.com
FOX RESOURCE=reddy17777@gmail.com
# Comment: Originally line 2 said RESOURCE=reddy17777@gmail.com
If you want to match only when RESOURCE=
appears at the beginning of a line,
use ^
:
sed 's/^RESOURCE=.*/RESOURCE=reddy17777@gmail.com/'
or
sed 's/^\(RESOURCE=\).*/\1reddy17777@gmail.com/'
If you want to replace only the resource value,
and not the entire rest of the line — e.g.,
RESOURCE=Lnreddy37@gmail.com TALENT=george@hotmail.com
to
RESOURCE=reddy17777@gmail.com TALENT=george@hotmail.com
that can be done, too.
Edit your question to say exactly what you want,
with full, clear explanations and examples.
OK, pick one of the above s
commands.
Now, if you want to edit your file in place (as you have indicated), do
sed -i { s command } { yourfile }
If you want to produce a new file, do
sed { s command } { oldfile } > { newfile }
Don’t actually type the {
and }
; they are there just for demarcation.