Find and replace text within a file when matched string found using commands

linux
text-processing
sed
bash

#1

I have a file which is having RESOURCE keyword. It may occur anywhere in the file, like:

RESOURCE=Lnreddy37atgmail_id_here

Now I want to replace Lnreddy37atgmail_id_here with reddy17777atgmail_id_here. So I have to search for the line where I can find the RESOURCE keyword and then replace the word after the equal sign. The RESOURCE keyword has to remain unmodified.

Could some one please help me on this. For example my input file sample.txt is as follows:

line 1
data 2
line 3
RESOURCE=Lnreddy37atgmail_id_here
foo
bar

Now i have to find out RESOURCE line and replace the Lnreddy37atgmail_id_here to reddy17777atgmail_id_here (could be any thing the replace word).

Pls help me


#2

I think try:

sed -i 's/RESOURCE=Lnreddy37atgmail_id_here/RESOURCE=reddy17777atgmail_id_here/' Sample.txt

If multiple replacement needed:

sed -i 's/RESOURCE=Lnreddy37atgmail_id_here/RESOURCE=reddy17777atgmail_id_here/g' Sample.txt