Re: Perl/unix script to convert a fixed width file to a tab delimited file
- From: gbacon@xxxxxxxxxx (Greg Bacon)
- Date: Sat, 29 Sep 2007 14:32:41 -0000
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
.
- References:
- Prev by Date: Re: string concatentation vs. interpolation: which one is more optimal?
- Next by Date: Re: Perl/unix script to convert a fixed width file to a tab delimited file
- Previous by thread: Perl/unix script to convert a fixed width file to a tab delimited file
- Next by thread: Re: Perl/unix script to convert a fixed width file to a tab delimited file
- Index(es):
Relevant Pages
|