Bash replace the string after the keyword

微信扫一扫,分享到朋友圈

Bash replace the string after the keyword

In the file I have a line that says 1|host|google.com

I need to change the keyword after “host|”. There are different hosts in each file. I cannot just replace google.com as the keyword after “host|” is not the same in each file.

sed -i 's/^1|host|*$/1|host|"NewHostname"/' ."FileName"

That way you replace:

host|somethingsomethingsomething

with

host|NewHostName

and directly write it into a file named FileName

^
marks the beginning of a line and $
the end so you apply your Pattern to the whole line.

*
matches everything so every hostname is replaced

here you can find some general knowledge about sed, since this was some basic stuff

Link to GNU

微信扫一扫,分享到朋友圈

Bash replace the string after the keyword

1889元!华为新款手表完全曝光:1.4英寸大表盘,续航半月

上一篇

定位 决战于心智!

下一篇

你也可能喜欢

Bash replace the string after the keyword

长按储存图像,分享给朋友