I want to sort the generated DDL of a database by name of the object. For example, I have the following DDL:
CREATE TABLE MyTable3 (
col1 integer,
col2 varchar(10)
);
CREATE TABLE MyTable1 (
col1 integer
);
CREATE TABLE MyTable2 (
col1 integer,
col2 varchar(10),
time timestamp
time2 timestamp
);
And I want the following output:
CREATE TABLE MyTable1 (
col1 integer
);
CREATE TABLE MyTable2 (
col1 integer,
col2 varchar(10),
time timestamp
);
CREATE TABLE MyTable3 (
col1 integer,
col2 varchar(10)
);
I have tried with awk, but I do not know to specify multiple lines: awk -F; '{print $NB}'
I found that msort could be the solution, but this package is not longer maintained.
As you can see, each element can have different quantity of lines, and I want to sort them by the first line which contains the name of the object.
What other options do I have to sort a document by multiple lines and a specific terminator (semi-colon).