Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    7

    Cool Unanswered: Convert txt file

    Hi all,

    I had a txt file in the following format :-

    John Kenedy Smith98 Victoria Street60000030M65234566

    and I want to convert it into

    John Kenedy Smith|98 Victoria Street|600000|30|M|65234566

    I'm wondering how can I write a little script to convert it into the following
    format because I just need the pipe to separate it into a different field so I can just upload it into the informix table.

    All help r welcome.

    Cheers

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by yfs_168us
    Hi all,

    I had a txt file in the following format :-

    John Kenedy Smith98 Victoria Street60000030M65234566

    and I want to convert it into

    John Kenedy Smith|98 Victoria Street|600000|30|M|65234566

    I'm wondering how can I write a little script to convert it into the following
    format because I just need the pipe to separate it into a different field so I can just upload it into the informix table.

    All help r welcome.

    Cheers

    nawk -f yfs.awk myFile.txt

    here's the yfs.awk

    Code:
    BEGIN {
      OFS="|"
    }
    
    {
      i=match($3, /[0-9]/);
      name = $1 FS $2 FS substr($3,1,i-1)
      j=match($5, /[0-9]/);
      addr = substr($3,i) FS $4 FS substr($5,1,j-1);
      last=substr($5, j);
      alphaCodeI=match(last, /[^0-9]/);
      a4=substr(last, alphaCodeI+1);
      a3=substr(last, alphaCodeI,1);
      a2=substr(last, alphaCodeI-2,2);
      a1=substr(last, 1, alphaCodeI-3);
      print name, addr, a1,a2,a3,a4
      #printf("name->[%s] addr->[%s] a1->[%s] a2->[%s] a3->[%s] a4->[%s]\n", name, addr, a1, a2,a3, a4);
    }
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •