Search through a word till end of line with sed in Linux Bash Shell.
Today we will see how to search starting from a word, and then select text till end of the line with sed command in linux bash shell.
Lets see step by step to understand this.
1. Search for a word say “XYZ”.
[root@ngelinux001 oracle]# cat oraclecfg.bak | grep -i XYZ # The hostname or IP of master control gateway (XYZ) #XYZ=your gateway domain name or IP address
2. Now select whole line using “*”.
[root@ngelinux001 oracle]# sed -i 's/#XYZ=*/XYZ="web.ngelinux.com"/g' oraclecfg.bak
3. Check out the whole text is replaced now.
[root@ngelinux001 oracle]# cat oraclecfg.bak | grep -i XYZ # The hostname or IP of master control gateway (XYZ) XYZ="web.ngelinux.com" [root@ngelinux001 oracle]#
So here, we have used this trick to replace a line with our new line automatically via a command.