neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

I have some tables like this:
blah blah ;; yada yada ;; etc etc
A much longer field ;; yada yada ;; etc etc
Each field can be any width. I want to align the columns including the delimiters. A command like column removes the delimiter. I want to keep the delimiter. I thought this would have been done already, but I can't find anything. So I'm turning to Perl. Again I thought someone would have done this before, but my search has turned up empty. Do I have to roll my own?

UPDATE: You can scrub this node. This works:

cat file.txt |sed -e 's/;;/;;@@/g' | column -s '@@' -t
It adds a second, temporary delimiter.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Aligning delimited columns
by hbm (Hermit) on May 31, 2013 at 14:19 UTC

    No need to pipe the file into sed (i.e., why read the file twice?)

    sed 's/;;/;;@@/g' file.txt | column -s '@@' -t
Re: Aligning delimited columns
by ww (Archbishop) on May 31, 2013 at 17:53 UTC

    Keep the delimiter? See perldoc -f split

    #!/usr/bin/perl use 5.016; use Data::Dumper; my $text = "blah blah ;; yada yada ;; etc etc \n A much longer field ;; yada yada ;; etc etc"; my @arr = split /(;;)/,$text; # capture delimiter say Dumper @arr;

    Is this what you mean you say you want to keep the delimiter?

    C:\> 1036247.pl $VAR1 = 'blah blah '; $VAR2 = ';;'; $VAR3 = ' yada yada '; $VAR4 = ';;'; $VAR5 = ' etc etc A much longer field '; $VAR6 = ';;'; $VAR7 = ' yada yada '; $VAR8 = ';;'; $VAR9 = ' etc etc';

    If you didn't program your executable by toggling in binary, it wasn't really programming!