[118231] in Cypherpunks
Re: fixed length
daemon@ATHENA.MIT.EDU (Ryan Permeh)
Wed Sep 22 10:43:10 1999
Message-ID: <37E8E37D.4C558025@rconnect.com>
Date: Wed, 22 Sep 1999 09:11:10 -0500
From: Ryan Permeh <rrpermeh@rconnect.com>
MIME-Version: 1.0
To: Richard Simpson <Richard.Simpson@sitel.com>
CC: "'cypherpunks@toad.com'" <cypherpunks@toad.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: Ryan Permeh <rrpermeh@rconnect.com>
Richard Simpson wrote:
> hi I have a problem, i need to convert a csv data file (each containing
> about 30 fields) into a fixed length format in unix, is there a program
> availible?
>
> Richard Simpson
> Telecoms Engineer
> SITEL UK
> Tel: 020 8784 1224 (3302 1224)
> Mobile: 0467 277714 (3402 1224)
> EMail: Richard.Simpson@SITEL.COM
Perl Is fantastic for this, use the split command (split each line up on
whatever your delimeter is) to cut up the input, and then standard printf
per line of input to output in the format that wou are looking for.
something like this
#!/bin/perl
while (<>)
{
my @out = split (",",$_);
printf("%4s%9s%3s",$out[0].$out[1],$out[2]);
}
You would have to adjust the #'s in the printf(and add as many $out[] bits
of the out array as nessecary) and perhaps change the comma in the split
for whatever your delimeter is.
then just call it like this:
cat blah.csv | myfilter.pl > nicelyformattedoutput
Ryan