I'm not 100% sure, but is this what you are after?
#!/usr/bin/perl -w use strict; while (my $line=<DATA>) { chomp $line; my @f=split(",",$line); my $fmt = sprintf("%s","%10s" x 5) . "\n"; printf $fmt,@f; } __END__ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ 123456,12/01/2004,ABCDEFG,12345 ,XYZ
When that code is run you get:
12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ 12345612/01/2004 ABCDEFG 12345 XYZ
Not sure what you mean by "fixed length" or what your criteria for the proper field width is, but the principle remains the same.
In future you'd get better responses if you are more specific about what your requirements are.
In reply to Re: convert a comma delimited file to a fixed length
by blue_cowdawg
in thread convert a comma delimited file to a fixed length
by tariqahsan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |