Converting Delimited Files with Perl (Help!)

Darren Reely darren.reely@latticesemi.com
Thu, 08 Nov 2001 15:21:38 -0800


For those whe care, another possibility...

Try the unix command 'expand'.  Do a man expand.

For the sample I sent earlier the following works:
  expand -50 input.txt >output.txt

Darren


Darren Reely wrote:

> I've played with this a bit I think the following is what you want:
> 
> perl -e 'use Text::Tabs; $tabstop=50;while (<>) {print expand($_); } ' <
> input.txt > output.txt
> Darren Reely
> 
> Karen Barrett wrote:
> >
> > Recently Tom Patton posted a solution to expanding a delimited file to fixed
> > width using Perl.  This looked pretty good to me as I have a tab delimited
> > file that is giving us big headaches. Yours truly who can barely stagger
> > around Unix  is trying to revise the examples.
> >
> > # Replace with tabs:
> > perl -e 'while (<>) {tr/|/\t/; print; } < oldfile > newfile
> >
> > #Blank-pad with arbirtrary field width (10 in this example)
> > perl -e 'use Text::Tabs; $tabstop=10; while (<>) { tr/|/\t;
> >    print expand($_); }' < oldfile > newfile
> >
> > My first effort :
> > perl -e 'while (<>) {tr/\t/""/;  print; } ' < segments.txt > seg2.txt
> > removed some but not all of the tabs.
> >
> > My second effort:
> > perl -e 'use Text::Tabs; $tabstop=50;while (<>) {tr/\t/""/; print expand
> > ($_); } ' < segments.txt > segnew.txt
> > Generated the following -
> > syntax error in file /tmp/perl-ea24890 at line 1, next 2 tokens "use Text"
> > Execution of /tmp/perl-ea24890 aborted due to compilation errors.
> >