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



In article <1191072950.845896.75120@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Srikant <srikantics@xxxxxxxxx> wrote:

: 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
--
Human ingenuity, not government, solves the problem of scarcity. The
nations in which poverty is greatest are those that restrain human
ingenuity -- that is, freedom -- and punish initiative.
-- Wendy McElroy
.



Relevant Pages