Sets of lines delimited by # to single lines
In fact, all proposed solutions so far have some gotcha. besides the
leading/trailing space problems, it's also problematic with the record
rebuilding when there are TABs or adjacent whitespaces in a record.
here are some other solutions:
awk -v RS="\n#" '{ gsub(/\n/," "); gsub(/^ | $/,"") }1'
or
{
if ($0 ~ /^#/) {
SP = "\n";
} else {
printf("%s%s", SP, $0);
SP = " ";
}
}
or use two s/// commands in sed/perl:
sed -n 'H;$ba;/^#/{:a;x;s/\n/ /g;s/^#\? \| #\?$//g;p;}'
perl -lp043e 's/\n/ /g;s/^ | $//g'
Regards,
Xicheng
|