Skip to main content
\s is a gnu extension, use [[:blank:]] if you want it to work with all `sed`s
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

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 ); 
  • N Read/append the next line of input into the pattern space.
  • P Print up to the first embedded newline of the current pattern space.
  • D Delete 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.

Using 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 ); 
  • N Read/append the next line of input into the pattern space.
  • P Print up to the first embedded newline of the current pattern space.
  • D Delete 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.

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 ); 
  • N Read/append the next line of input into the pattern space.
  • P Print up to the first embedded newline of the current pattern space.
  • D Delete 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.
added 73 characters in body
Source Link
Siva
  • 9.3k
  • 9
  • 60
  • 88

Using sed:

sed 'N;s/,\(\s*\nPRIMARY\\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 ); 
  • N Read/append the next line of input into the pattern space.
  • P Print up to the first embedded newline of the current pattern space.
  • D Delete 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.

Using sed:

sed 'N;s/,\(\s*\nPRIMARY\)/)\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 ); 

Using 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 ); 
  • N Read/append the next line of input into the pattern space.
  • P Print up to the first embedded newline of the current pattern space.
  • D Delete 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.
Source Link
Siva
  • 9.3k
  • 9
  • 60
  • 88

Using sed:

sed 'N;s/,\(\s*\nPRIMARY\)/)\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 );