Append repeated text using sed or awk? -
i have following config file:
servers = ( { host = "localhost"; ... timeout = 5; }, { host = "127.0.0.1"; ... timeout = 0; }, { host = "example.com"; ... timeout = 99; } );
i want append "index" setting @ end of each section config this:
servers = ( { host = "localhost"; ... timeout = 5; index = 1; }, { host = "127.0.0.1"; ... timeout = 0; index = 2; }, { host = "example.com"; ... timeout = 99; index = 3; } );
how can conventional unix tools sed or awk?
this adds line index = ...
after each line has timeout
first word.
awk '1;$1=="timeout"{printf " index = %d;\n", ++i}' file
Comments
Post a Comment