perl -lne 'sub out { s/\s+/ /g, print for @t; # Normalize whitespace, print buffers. @t = (); # Clear the buffers. } if (/^-+$/) { # Separator. out(); } else { @p = split /\|/; # Split the line on vertical bars. $t[$_] .= $p[$_] for 0 .. $#p; # Add each part to its buffer. }' < input #### }{ out();