I've got a file.sql file from an informix database export.
The following is a small part of the file (I changed the data a little bit to make it anonymous):
grant dba to "xxx";
grant dba to "yyy";
grant dba to "zzz";
{ TABLE "xxx".table1 row size = 66 number of columns = 5 index size = 54 }
{ unload file name = table00100.unl number of rows = 307 }
create table "xxx".table1
(
field1 char(2) not null ,
field2 char(10) not null ,
field3 char(30),
field4 char(20) not null ,
field5 date not null
);
revoke all on "xxx".table1 from "yyy";
What I need from this file is to name the table00100.unl file back to the original table name. So I need an output like this:
mv table00100.unl table1
I've managed to to this with 2 files in between with a little of awk and sed, but isn't this possible in an easier way without the temporary files in between? My code sample:
awk '{for(i=1;i<=NF;i++) {if ($i=="unload") {print $(i+4)} else {if ($i=="TABLE") print $(i+1)}}}' file.sql | sed 's/".*".//' > temp.out
awk 'NR%2{printf "%s ",$0;next;}1' temp.out | awk '{for (i=NF;i>0;i--) if (i > 1) printf("mv %s ",$i); else printf("%s\n",$i)}' > temp.shl