Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl/unix script to convert a fixed width file to a tab delimited file

Reply
Thread Tools

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

 
 
Srikant
Guest
Posts: n/a
 
      09-29-2007
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

 
Reply With Quote
 
 
 
 
Greg Bacon
Guest
Posts: n/a
 
      09-29-2007
In article <(E-Mail Removed). com>,
Srikant <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting pipe delimited file to fixed width digz Python 5 03-19-2009 05:40 PM
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
A Script To Convert iTunes XML To Tab Delimited Format jean@vaneskahian.com Perl Misc 7 05-27-2006 08:37 PM
Translate tab-delimited to fixed width text mike beck Python 2 09-30-2004 04:12 PM
Is there any perl script for converting XML file to tab-delimited file ? gongwuming@hotmail.com Perl Misc 1 04-14-2004 05:15 PM



Advertisments