With the sed editorsed tool, you can do like shown:
sed -i -e '
/^\(\([^|]*|\)\{2\}\)*[^|]*$/b
N;s/\n/ /
s/^/\n/;D
' . /*.csv
Method###Explanation:
° branch to end of sed code processing for the current pattern space data when an even number of pipes are found.
° or, go fetch the next line and append it to the pattern space.
° now reapply the sed code all over again on the pattern space.
perl -i.BAK -lpe '
$\ = ( $k += tr/|/|/ ) =~ /[24680]$/ ? "\n" : " ";
' . /*.csv
° $k is a running counter of number if pipes seen at any time.
° for even we print with a newline, otherwise we join the lines with a space.
Branch to end of
sedcode processing for the current pattern space data when an even number of pipes are found.Or, go fetch the next line and append it to the pattern space.
Now reapply the
sedcode all over again on the pattern space.perl -i.BAK -lpe ' $\ = ( $k += tr/|/|/ ) =~ /[24680]$/ ? "\n" : " "; ' . /*.csv$kis a running counter of number if pipes seen at any time.For even we print with a newline, otherwise we join the lines with a space.