 <p>This might work for you (GNU sed):</p> <pre><code>sed -r 's#.*#s/.*/&amp;=\&amp;/#;1s#$#;h#;1!s#.*#n;&amp;;H#;$s#$#;x;s/^([^\\n]*)\\n(.*)/update.database.table set \\2 WHERE \\1;/;s/\\n/, /gp#' file | sed -nrf - log </code></pre> <p>Turn the file into a sed script then run it against the log.</p>