Let's consider a SQL file as input (i.e. myTable.sql) containing the following statement :
EXECUTE IMMEDIATE 'CREATE OR REPLACE PUBLIC SYNONYM ' || myTable || ' FOR SCHEMA1.' || myTable;
Is there a simple way (using sed) to duplicate this statement and modify them as follows ?
EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM SCHEMA2.' || myTable || ' FOR SCHEMA1.' || myTable;
EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM SCHEMA3.' || myTable || ' FOR SCHEMA1.' || myTable;
Thanks a lot for your help. M.
* EDIT *
First part can be solved like this :
sed -i -e '/PUBLIC SYNONYM/p' myTable.sql
Second part is about two search-and-replace commands :
sed -i -e '0,/PUBLIC SYNONYM/s/PUBLIC SYNONYM /SYNONYM SCHEMA2./' myTable.sql
sed -i -e '0,/PUBLIC SYNONYM/s/PUBLIC SYNONYM /SYNONYM SCHEMA3./' myTable.sql
I consider my question has been answered. Feel free to reply if you find something more efficient. Cheers.
First part can be solved like this :
sed -i -e '/PUBLIC SYNONYM/p' myTable.sql
Second part is about two search-and-replace commands :
sed -i -e '0,/PUBLIC SYNONYM/s/PUBLIC SYNONYM /SYNONYM SCHEMA2./' myTable.sql
sed -i -e '0,/PUBLIC SYNONYM/s/PUBLIC SYNONYM /SYNONYM SCHEMA3./' myTable.sql
I consider my question has been answered. Feel free to reply if you find something more efficient. Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With