I have the following script....
if(!found && match($0, PATstart)) {
found=1;
printf("%s", substr($0, 1, RSTART-1));
next;
}
if( found && match($0, PATend)) {
printf("%s%s\n", PATsubst, PATend);
if (RSTART+RLENGTH+1 < length($0))
printf("%s\n", substr($0, RSTART+RLENGTH+1));
found=0;
next;
}
if (!found) print
}
the idea is to pass it a file of SQL statements and strip out junk at the end and replace it with some standard text.
eg.
awk -f ${awk_cmd} "PATstart=\"PARTITION BY\"" \
"PATend=\";\"" "PATsubst=\"\"" ${create_script}_table >>${create_script}_table2
This works fine - any multiline command that has PARTITION BY in it gets replaced with just a semicolon.
However if my PATstart contains, say a open bracket, I get mismatched () - it seems to be interpretng the bracket inside the quotes
....
awk -f ${awk_cmd} "PATstart=\"LOCAL(PARTITION\"" \
"PATend=\";\"" "PATsubst=\"\"" ${create_script}_table >>${create_script}_table2
I get...
@fawk: There is a regular expression error.
() imbalance.
The input line number is 1. The file is /tmp/./customer_import_25963.sql_index.
The source line number is 1.
I've also tried hardcoding an example in a dummy awk file...
$ cat glm2_awk.cmd
BEGIN { PATstart="PARTITION(BY";
PATend=";";
PATsubst=""
}
{print PATstart;
if(!found && match($0, PATstart)) {
found=1;
printf("%s", substr($0, 1, RSTART-1));
next;
}
if( found && match($0, PATend)) {
printf("%s%s\n", PATsubst, PATend);
if (RSTART+RLENGTH+1 < length($0))
printf("%s\n", substr($0, RSTART+RLENGTH+1));
found=0;
next;
}
if (!found) print
}
$ awk -f glm2_awk.cmd index2.sql
PARTITION(BY
awk: There is a regular expression error.
() imbalance.
The input line number is 1. The file is index2.sql.
The source line number is 6.
I'm new to awk so any help would be appreciated
if(!found && match($0, PATstart)) {
found=1;
printf("%s", substr($0, 1, RSTART-1));
next;
}
if( found && match($0, PATend)) {
printf("%s%s\n", PATsubst, PATend);
if (RSTART+RLENGTH+1 < length($0))
printf("%s\n", substr($0, RSTART+RLENGTH+1));
found=0;
next;
}
if (!found) print
}
the idea is to pass it a file of SQL statements and strip out junk at the end and replace it with some standard text.
eg.
awk -f ${awk_cmd} "PATstart=\"PARTITION BY\"" \
"PATend=\";\"" "PATsubst=\"\"" ${create_script}_table >>${create_script}_table2
This works fine - any multiline command that has PARTITION BY in it gets replaced with just a semicolon.
However if my PATstart contains, say a open bracket, I get mismatched () - it seems to be interpretng the bracket inside the quotes
....
awk -f ${awk_cmd} "PATstart=\"LOCAL(PARTITION\"" \
"PATend=\";\"" "PATsubst=\"\"" ${create_script}_table >>${create_script}_table2
I get...
@fawk: There is a regular expression error.
() imbalance.
The input line number is 1. The file is /tmp/./customer_import_25963.sql_index.
The source line number is 1.
I've also tried hardcoding an example in a dummy awk file...
$ cat glm2_awk.cmd
BEGIN { PATstart="PARTITION(BY";
PATend=";";
PATsubst=""
}
{print PATstart;
if(!found && match($0, PATstart)) {
found=1;
printf("%s", substr($0, 1, RSTART-1));
next;
}
if( found && match($0, PATend)) {
printf("%s%s\n", PATsubst, PATend);
if (RSTART+RLENGTH+1 < length($0))
printf("%s\n", substr($0, RSTART+RLENGTH+1));
found=0;
next;
}
if (!found) print
}
$ awk -f glm2_awk.cmd index2.sql
PARTITION(BY
awk: There is a regular expression error.
() imbalance.
The input line number is 1. The file is index2.sql.
The source line number is 6.
I'm new to awk so any help would be appreciated