Hi,
I've a gawk script wich work fine with gawk but on the IBM AIX server I've just awk, the script doesn't work with awk, I've got this error :
$ awk -f awk_sql2.awk
syntax error The source line is 1. The function is parseCreate.
The error context is
<<< function parseCreate(t) >>> {
awk: The statement cannot be correctly parsed.
The source line is 1. The function is parseCreate.
syntax error The source line is 2. The function is parseCreate.
What I have to modify to get the script work with awk?
The script :
Regards
I've a gawk script wich work fine with gawk but on the IBM AIX server I've just awk, the script doesn't work with awk, I've got this error :
$ awk -f awk_sql2.awk
syntax error The source line is 1. The function is parseCreate.
The error context is
<<< function parseCreate(t) >>> {
awk: The statement cannot be correctly parsed.
The source line is 1. The function is parseCreate.
syntax error The source line is 2. The function is parseCreate.
What I have to modify to get the script work with awk?
The script :
Code:
function parseCreate(t) {
match(t, /^CREATE TABLE : ([^;[:space:]]+);([^[:space:]]+) AS$/, a)
if ( 2 in a ) {
Program = a[1]
Table = a[2]
}
}
function parseSelect(t) {
match(t, /^SELECT : ([^;[:space:]]+);([^[:space:]]+)$/, a)
if ( 2 in a ) {
if ( a[1] == Program ) {
delete Select
split(a[2], Select, ",")
}
}
}
function parseFrom(t) {
match(t, /^FROM : ([^;[:space:]]+);([^;]+)$/, a)
if ( 2 in a ) {
if ( a[1] == Program ) {
split(a[2], b, ",")
delete From
for ( n in b ) {
match(b[n], /([^[:space:]]+) ([^[:space:]]+)/, a)
if (2 in a) {
From[a[2]] = a[1]
} else {
From[0] = b[n]
}
}
}
}
}
BEGIN {
Program = "MISSING"
}
/^CREATE/ { parseCreate($0) }
Program != "MISSING" {
if ($0 ~ /^SELECT/) {
parseSelect($0)
}
if ($0 ~ /^FROM/) {
parseFrom($0)
for (n in Select) {
match(Select[n], /([^.]+)\.([^.]+)/, a)
if ( 2 in a ) {
print Program,";",Table,";",From[a[1]],";",a[2]
} else {
print Program,";",Table,";",From[0],";",Select[n]
}
}
Program = "MISSING"
}
}
Regards