Converting Delimited Files with Perl (Help!)

Pickering, John (NORBORD) PICKERIJ@norbord.com
Thu, 8 Nov 2001 16:44:26 -0500


Do you want a sample Qtp which dismantles a tab delimited file into a bunch
of sensible fields and puts them in a subfile?

You were asking the question of the PowerHouse list weren't you?



> -----Original Message-----
> From:	Karen Barrett [SMTP:kbarrett@denkor.com]
> Sent:	Thursday, November 08, 2001 4:16 PM
> To:	PowerhouseList
> Subject:	Converting Delimited Files with Perl (Help!)
> 
> 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.
> 
> This looks to be my only foray into Unix/Perl on the horizon for some
> time.
> If I am making a simple error (or errors), can someone steer me? I was
> unsuccessful in my attempts to email Tom offline.
> 
> Karen Barrett
> Senior Program Analyst
> Denkor Dental Management Corp.
> Portland, OR.
>