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 ?
Thanks
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 ?
Thanks