Converting Delimited Files with Perl (Help!)
Karen Barrett
kbarrett@denkor.com
Thu, 8 Nov 2001 13:15:51 -0800
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.