Perl/unix script to convert a fixed width file to a tab delimited file

S

Srikant

Hi all,
I have a situtation here. We have a script that reads two
delimited (comma or tab or pipe or semicolon or any other) files and
compares them returnig the list of records/rows unique to file1,
unique to file2 and the mismatches records.
Now, we also have to get this going for fixed width files. I
know that the inbuilt excel tool, Text to columns, does this. However
we need to get this process automated on the unix box.
Any suggestions? If someone can help me with the scipt itself,
that'll be awesome.


Thanks a lot.

Regards
Srikant
 
G

Greg Bacon

: I have a situtation here. We have a script that reads two
: delimited (comma or tab or pipe or semicolon or any other) files and
: compares them returnig the list of records/rows unique to file1,
: unique to file2 and the mismatches records.
: Now, we also have to get this going for fixed width files. I
: know that the inbuilt excel tool, Text to columns, does this. However
: we need to get this process automated on the unix box.

Something like the following?

$ cat try
#! /usr/bin/perl

use warnings;
use strict;

while (<DATA>) {
chomp;

my @f = unpack "A5A5A5", $_;

print join("," => @f), "\n";
}

__DATA__
R1 Five5Hello
Row2 ThreeBye

$ ./try
R1,Five5,Hello
Row2,Three,Bye

See also `perldoc -q fixed`.

Hope this helps,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top