I have a file that is full of lines like:
snprintf(log_buffer,...
...
...
...
);
If I use sed, I can find these lines with "snprint.*log_buffer".
My issue is, I would like to add a line after the ; of the statement:
send_to_logger_process(log_buffer);
However I cannot blindly add a line to the line after the match string, as the snprintf line can be multiple lines.
Any idea of how to make this work for sed or awk, or some other command line tool so I can do it to all the files in a directory? You can assume that there are no semicolons (;) within the body of the snprintf: the only ; is at the end of the statement.
edit 01: the solution:
sed '/snprint.*log_buffer/,/;/ s/;/;\nsend_to_logger_process(log_buffer);/'
has some false positives:
static struct option long_options[] =
{
/* These options set a flag. */
{"verbose", no_argument, &verbose_flag, 1},
{"brief", no_argument, &verbose_flag, 0},
/* These options dont set a flag.
We distinguish them by their indices. */
{"chipaddr_led", required_argument, 0, 'c'},
{"togglepaddr", required_argument, 0, 't'},
{"regaddr", required_argument, 0, 'r'},
{"value", required_argument, 0, 'v'},
{"i2cport", required_argument, 0, 'i'},
{"led", required_argument, 0, 'l'},
{"mstime", required_argument, 0, 'm'},
{"dutycyle", required_argument, 0, 'd'},
{"status", required_argument, 0, 's'},
{0, 0, 0, 0}
};
send_to_logger_process(log_buffer);