in reply to tricky text file

Process the table line by line. Keep an array of text buffers (@t), if the line contains data, split it on |'s and add each part to a corresponding text buffer. If the line contains only ---'s, output the buffers and clear them.
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 vert +ical bars. $t[$_] .= $p[$_] for 0 .. $#p; # Add each part to its b +uffer. }' < input

If the last line in the input is not a --- line, you'll need to add

}{ out();

to the end of the script to print the last accumulated buffers.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: tricky text file
by raidermike (Initiate) on Sep 10, 2015 at 13:55 UTC
    ah, very cool