Hi recently I've posted a problem.
edit nth line below a line match in bash?
(Problem: I have to edit the PROTOCOL
line 3 lines below [MARATHON]
)
This is the file:
# /etc/ndxconfig.ini will override this file
# if APP_ID is added in service propery, service discovery will be using marathon;
# HOST/PORT specified will override values retrieved from marathon
[MARATHON]
HOSTS = {{ ','.join(groups['marathon'])}}
PORT = 8080
PROTOCOL = http
SECRET = SGpQIcjK2P7RYnrdimhhhGg7i8MdmUqwvA2JlzbyujFS4mR8M88svI7RfNWt5rnKy4WHnAihEZmmIUb940bnlYmnu47HdUHE
[MYSQL]
; APP_ID = /neon/infra/mysql
HOST = {{keepalived_mysql_virtual_ip}}
PORT = 3306
SECRET = tIUFN1rjjDBdEXUsOJjPEtdieg8KhwTzierD48JsgDeYc84DD6Uy5a6kzHfKolq1MNS1DKwlSqxENk33UulJd9DPHPzYCxFm
The problem is if I rerun the script in some case, the
sed '/\[MARATHON\]/{N;N;N;s/http/https/;}' <file>
will append more and more s
to http
(httpsssss
).
So I would add a positive lookahead in regex for s
.
I can do it with perl -pe but do not know how I do it on nth line below a match.
Please Help. How can I do it?