in reply to tricky text file
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 |