Using GNU sed:
sed 'N;s/,\(\s*\n.*PRIMARY\)/)\1/;P;D' file ID_SOUR_CALENDAR BIGINT NOT NULL DEFAULT 0 COMPRESS 0 ) UNIQUE PRIMARY INDEX ( CALENDAR_DATE ); ID , ID_SOUR ) PRIMARY INDEX ( CALENDAR_DATE ); NRead/append the next line of input into the pattern space.PPrint up to the first embedded newline of the current pattern space.DDelete up to the first embedded newline in the pattern space. Start next cycle, but skip reading from the input if there is still data in the pattern space.