Delete patterns matching

Delete patterns matching

OS version: RHEL 7.3
Shell : Bash

I have a file like below (pattern.txt). I need to delete all lines starting with the following words (words separated by comma below) and ) character.

LOGGING, NOCOMPRESS, TABLESPACE , PCTFREE, INITRANS, MAXTRANS, STORAGE, INITIAL, NEXT, MINEXTENTS, MAXEXTENTS, BUFFERPOOL, )
Can this be done using sed or awk ?

$ cat pattern.txt
(
  PARTITION SYS_SUBP77865
    LOGGING
    NOCOMPRESS
    TABLESPACE OSM_ORDER_DATA
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          8M
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                BUFFER_POOL      DEFAULT
               ),
  PARTITION SYS_SUBP77866
    LOGGING
    NOCOMPRESS
    TABLESPACE OSM_ORDER_DATA
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          8M
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                BUFFER_POOL      DEFAULT
               ),
  PARTITION SYS_SUBP77867
    LOGGING
    NOCOMPRESS
    TABLESPACE OSM_ORDER_DATA
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          8M
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                BUFFER_POOL      DEFAULT
               ),
  PARTITION SYS_SUBP77868
    LOGGING
    NOCOMPRESS
    TABLESPACE OSM_ORDER_DATA
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          8M
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                BUFFER_POOL      DEFAULT
               ),
 

Expected output:

(
  PARTITION SYS_SUBP77865
  PARTITION SYS_SUBP77866
  PARTITION SYS_SUBP77867
  PARTITION SYS_SUBP77868
  .
  .
  .

Any attempts / ideas / thoughts from your side?

awk 'NR==FNR {c=split($0, no_match, " *, *"); for (i=1; i<=c; i++) del_line[no_match]=no_match ; next}
{gsub("[)]", ") ")}
! ($1 in del_line)
' no_match.txt pattern.txt

When you say "starting with" I don't see any lines that match that criteria because nearly all the lines have leading spaces. Do you really mean that you want to drop all lines that have the first non-blank/first word as those in your list?

What's wrong with something like grep -Ev "Cond1|Cond2|Cond3....." infile > outfile ?

The conditions would be expressions to describe what you need to exclude. The opposite could be simpler, i.e. use grep to select only the lines you do want?

Robin