SpiritOfLennon
IS-IT--Management
Hi,
I'm trying to write an awk script to create audit tables and triggers for an Oracle database but I'm having problems with my array.
Sample input is
AAAAA|BBBBB
AAAAA|CCCCC
AAAAA|DDDDD
EEEEE|FFFFF
EEEEE|GGGGG
I want my output to be
AAAAA|BBBBB|CCCCC|DDDDD
EEEEE|FFFFF|GGGGG
Could anyone make any suggestions? I have
BEGIN { FS="|" ; cnt = 0 +1 }
TABLE[NR] = $2
COLUMN[NR] = $3
FIELD[NR] = $4
LENGTH[NR] = $5
PRECISION[NR] = $6
NULL[NR] = $8
END {for(i=1;i<=NR;i++)
{ if (TABLE[i+1] != TABLE) cnt2 = i + 1
} { if(TABLE[i+1] != TABLE) {print "create table "TABLE" ("
{ for (j=cnt;j<=i;j++)
print COLUMN[j]" "FIELD[j]"("LENGTH[j]","PRECISION[j]" "NULL[j]
cnt = cnt2
} }
} }
SOL
I'm only guessing but my guess work generally works for me.
I'm trying to write an awk script to create audit tables and triggers for an Oracle database but I'm having problems with my array.
Sample input is
AAAAA|BBBBB
AAAAA|CCCCC
AAAAA|DDDDD
EEEEE|FFFFF
EEEEE|GGGGG
I want my output to be
AAAAA|BBBBB|CCCCC|DDDDD
EEEEE|FFFFF|GGGGG
Could anyone make any suggestions? I have
BEGIN { FS="|" ; cnt = 0 +1 }
TABLE[NR] = $2
COLUMN[NR] = $3
FIELD[NR] = $4
LENGTH[NR] = $5
PRECISION[NR] = $6
NULL[NR] = $8
END {for(i=1;i<=NR;i++)
{ if (TABLE[i+1] != TABLE) cnt2 = i + 1
} { if(TABLE[i+1] != TABLE) {print "create table "TABLE" ("
{ for (j=cnt;j<=i;j++)
print COLUMN[j]" "FIELD[j]"("LENGTH[j]","PRECISION[j]" "NULL[j]
cnt = cnt2
} }
} }
SOL
I'm only guessing but my guess work generally works for me.