How can I identify the beginning of a line with a special pattern and add something to the end of the line?
if the template to be added is not yet added
Suppose I would like to find a specific line in the host file, either by the template at the beginning it can be an IP address, or a comment above the line
An example would be:
#This is your hosts file
127.0.0.1 localhost linux
#This is added automatically
192.168.1.2 domain1. com
#this is added automatically to
192.168.1.2 sub.domain1.com www.domain1.com
How to tell bash when you find the IP address that I will tell you. go ro lines end and add something
or in another case
When bash finds a comment #This is added automatically
go down to 2 and then go to the end of the line and add something
You see that I am new and have no idea what to use here and how. Is this done by sed? or can this be done with grep? Should I learn AWK for this?