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

Discussion in 'Perl Misc' started by Srikant, Sep 29, 2007.

  1. Srikant

    Srikant Guest

    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
     
    Srikant, Sep 29, 2007
    #1
    1. Advertising

  2. Srikant

    Greg Bacon Guest

    In article <>,
    Srikant <> 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
     
    Greg Bacon, Sep 29, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike beck
    Replies:
    2
    Views:
    717
    mike beck
    Sep 30, 2004
  2. RyanL
    Replies:
    6
    Views:
    695
    Paul McGuire
    Aug 28, 2007
  3. digz
    Replies:
    5
    Views:
    2,158
    Tim Chase
    Mar 19, 2009
  4. Replies:
    1
    Views:
    335
    ZedGama3
    Apr 14, 2004
  5. Replies:
    7
    Views:
    272
    Guest
    May 27, 2006
Loading...

Share This Page