confi.ini (BEFORE)
[DEFAULT]
## Default settings ######################
debug = false
[app:main]
abc=def
ghfi=kftest
## General settings ######################
use=hello
test1.test2=test3
[logger]
level=INFO
handlers=console
extra_conf.ini
security.host=localhost
security.username=test
security.password=test12345
Can I know how do I use command to insert the extra_conf.ini file content into the confi.ini, under the [app.main]? I googled and found sed command, but I can't seem to do it as per the expected_confi.ini file, can someone please assist?
expected_confi.ini (AFTER changed)
[DEFAULT]
## Default settings ######################
debug = false
[app:main]
security.host=localhost
security.username=test
security.password=test12345
abc=def
ghfi=kftest
## General settings ######################
use=hello
test1.test2=test3
[logger]
level=INFO
handlers=console
Yes, you can use
sedto print just part of a file.It's import to understand
sedprocess one line at a time, printing the result. The basic usage is to match a string and execute a command.So you can get your desired file by:
Print lines from confi.ini, up to
[app:main]:sed "/\[app:main\]/q" confi.ini, where theqcommand quits sed, so we're printing everything until finding[app:main].Print all lines from extra_conf.ini:
cat extra_conf.iniPrint lines from confi.ini, except the ones from the start to
[app:main]:sed "1,/\[app:main\]/d" confi.ini, where thedcommand deletes lines 1 to the line with[app:main].Redirecting to new_conf.ini and putting it all together in a single-line command.
Be sure that
extra_conf.inihas no line break at the end.