[shell] Modify ini configuration file

There is a configuration file config.ini with the following contents:

[host]
host_conf=appts.xxxx.com

I want to modify the content of host_conf = appts.xxxx.com (pre-production environment) to host_conf = appapi.xxxx.com (online environment)

The configuration script is as follows:

= Host appapi.xxxx.com test data 
host_env = " hostconf Host} {$ = "  # Note here that double quotes 
Line = $ (Sed -n ' / the host_conf / = ' the config.ini) to modify the file # acquires the line number 
newline = $ (expr $ line- 1 ) #Calculate the new position of the inserted file (use append to modify the text later, so here line- 1 ) 
sed   -i   " $ line d "    config.ini # delete line 
sed -i " $ {newline} a \\ $ {host_env} " config.ini # Write the stitched string to the line

Implementation effect:

File modification takes effect

 

Guess you like

Origin www.cnblogs.com/kaerxifa/p/12737315.html