I'm editing my .uncrustify.cfg file to make it  more readable. I just want to reformat like this:Two lines in:# Add or remove between the parens in the function type: 'void (*x)(...)'sp_after_tparen_close      = ignore   # ignore/add/remove/forceOne line out:sp_after_tparen_close      = ignore   # ignore/add/remove/force#   Add or remove between the parens in the function type: 'void (*x)(...)'Perl seems to be the way to go, but the syntax overwhelms me. When I have a spare decade, I'll learn it ;-)To make it a bit more generic:Two lines in:#a comment linesome codeOne line out:some code # a comment line==========================John: Two lines done by hand:nl_while_brace             = ignore   # I,A,R,F     # Add or remove newline between 'while' and '{'nl_scope_brace             = ignore   # I,A,R,F     # Add or remove newline between 'scope (x)' and '{' (D)... two pairs that didn't combine using your awk:# Add or remove newline between 'unittest' and '{' (D)nl_unittest_brace          = ignore   # I,A,R,F# Add or remove newline between 'version (x)' and '{' (D)nl_version_brace           = ignore   # I,A,R,F
multiline editing using perl or any other tool
perl
sed '/^#/N;s/\(.*\)\n\([^#].*\)/\2 \1/;P;D'That will handle your simple example in the question - any commented line that is followed by a line that is not a comment and consists of at least one character will be appended to the line that follows it.So, running your example through it and the output is:sp_after_tparen_close      = ignore   # ignore/add/remove/force # Add or remove between the parens in the function type: 'void (*x)(...)'Running @John1024's example through it and the output is:## Some comments#sp_after_tparen_close      = ignore   # ignore/add/remove/force # Add or remove between the parens in the function type: 'void (*x)(...)'some code #a comment linemore code# comment one# comment twostill more code # comment threeTo handle conditions like these, sed needn't loop. In this case the only lines that can possibly contain a \newline character are those that begin with a #hash because those are the only lines to which sed will add one. When sed encounters a line beginning with a #hash it pulls in the Next input line and appends it to pattern space. sed then attempts to s///ubstitute:\(.*\) - as much as possible referenced as \1 immediately followed by...\n - a newline character immediately followed by...\([^#].*\) - at least one character that is not a #hash and everything remaining in pattern space...with \2 \1.sed then Prints pattern space up to the first occurring \newline character and Deletes same before starting over to try again with what remains (if any).