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);
}