I am in the process of porting an existing database schema to Postgresql.
I need to replace occurrences of the word 'go' with a semi comma.
I have noticed that the word 'go' appears in the text, in the following pattern:
- [non empty string (SQL)]
- [followed by one or more new lines]
- [followed by one or more white space]
- [followed by the word 'go']
- [Followed by one or more new lines]
I want to replace the above pattern with the following one:
- [non empty string (SQL)]
- [followed by ';']
- [Followed by TWO new lines]
I am trying to build a regex expression which I can use with sed, to perform the replacement described above - but I am relatively new to regex.
For the purpose of clarity, I have included sample text BEFORE and AFTER the substitution I want to achieve:
-- Original File contents below -------
go
CREATE TABLE foobar
(
f1 INT,
f2 INT,
f3 FLOAT,
f4 VARCHAR(32) NOT NULL,
f5 INT,
f6 datetime,
f7 smallint
)
go
GRANT UPDATE, INSERT, DELETE, SELECT ON foobar TO dbusr
go
CREATE UNIQUE INDEX idxu_foobar ON foobar (f1, f2)
go
--- REPLACED FILE CONTENTS -----------
go
CREATE TABLE foobar
(
f1 INT,
f2 INT,
f3 FLOAT,
f4 VARCHAR(32) NOT NULL,
f5 INT,
f6 datetime,
f7 smallint
);
GRANT UPDATE, INSERT, DELETE, SELECT ON foobar TO dbusr;
CREATE UNIQUE INDEX idxu_foobar ON foobar (f1, f2);
Can anyone help with the expression to use to achieve this, so I can execute:
sed -i 's/original_match_expr/replacement_expr/g' myfile.sql