Article 5QCQK linux find and replace specific string in specific line if rule match.

linux find and replace specific string in specific line if rule match.

by
dr.x
from LinuxQuestions.org on (#5QCQK)
Hello Folks ,

I have file called -->file.txt
#################
cc.com
hi my name is Albert from cc.com
#################

I want to make a rule to make check on line if the line contain 'Albert' then check same line and replace cc.com with xx.com .

sed -i "s/cc.com/xx.com/" file.txt

will result to :
###############
xx.com
hi my name is Albert from xx.com
#################

The issue is , I want only:

hi my name is Albert from cc.com to be replaced to ---> hi my name is Albert from xx.com

but it keep match all in all file .
My question is how to match specific rule in line and apply replacement in that matched line only ?

Thankslatest?d=yIl2AUoC8zA latest?i=QTOUL6VQ69U:C5S4aUagXho:F7zBnMy latest?i=QTOUL6VQ69U:C5S4aUagXho:V_sGLiP latest?d=qj6IDK7rITs latest?i=QTOUL6VQ69U:C5S4aUagXho:gIN9vFwQTOUL6VQ69U
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments