0

I have a code snippet like below

CREATE TABLE TABLE1(
  ID integer NOT NULL,
  ROW_CREATED varchar (26) NULL,
  BATCH_LOG_ID integer NULL,
  TRANSACTION_TYPE varchar(5) NULL,
  PARTITION_COL integer NOT NULL
) ON BASE_PARTITION (PARTITION_COL);

I want to change the code like below

CREATE TABLE TABLE1(
  ID integer NOT NULL,
  ROW_CREATED varchar (26) NULL,
  BATCH_LOG_ID integer NULL,
  TRANSACTION_TYPE varchar(5) NULL
) PARTITIONED BY (PARTITION_COL integer NOT NULL); 

Can this be done using a sed or awk?

  • I don't understand what you want to do. – Vouze Apr 9 '15 at 11:55
  • I want to change the DDL. There is a column on which partition defined PARTITION_COL integer NOT NULL. In the new DDL that column shouldn't be there in the column list rather it should come within the PARTITIONED BY clause – Koushik Chandra Apr 9 '15 at 11:59
  • This will also work for me if I can get a series of commands which I can put in a script – Koushik Chandra Apr 9 '15 at 13:51
0
'BEGIN{f=0} ; { if ($0 ~ "TRANSACTION_TYPE varchar\\(5\\) NULL,") { print ; printf("%-s", ") PARTITIONED BY (PARTITION_COL integer NOT NULL);") ; f=1 } else if (f==0) print }' inputfile

This will print the lines of the input file until it reaches the line with "varchar(5)" in it, where it prints that line followed by the new "PARTITIONED BY" line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.