Remove multiple lines from a particular string to particular string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove multiple lines from a particular string to particular string
# 1  
Old 05-02-2013
Remove multiple lines from a particular string to particular string

Hi,

I have a file containing the DDLs of tables in a schema. From that I need to remove all the lines from a starting string till a specific string. Here is an example.
File1.txt
-------------
Code:
  CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS"
   (    "ID" NUMBER(8,0) NOT NULL ENABLE,
    "USER_ID" VARCHAR2(10) NOT NULL ENABLE,
    "USER_NAME" VARCHAR2(50),
    "TEAM" NUMBER(8,0) NOT NULL ENABLE,
    "ROLE" NUMBER(8,0) NOT NULL ENABLE,
    "TITLE" VARCHAR2(50),
    "TEAM_MANAGER" VARCHAR2(50),
    "COMPUTER_NAME" VARCHAR2(50),
     CONSTRAINT "PK_LKP11" PRIMARY KEY ("ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA101"  ENABLE,
     CONSTRAINT "UQ_LKP11_USER_ID" UNIQUE ("USER_ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA101"  ENABLE
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA102"

  CREATE TABLE "SCHEMA1"."LKP07_CHECK_PAYMENT_PLAN"
   (    "PAYMENT_PLAN" VARCHAR2(3),
    "PMS_FLAG" VARCHAR2(1),
     CONSTRAINT "PK_PAYMENT_PLAN" PRIMARY KEY ("PAYMENT_PLAN")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA102"  ENABLE
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA102"

------------------------

In the above file I am searching for "USING INDEX" and it will remove all the lines starting from the line having "USING INDEX" till it founds ")"

The o/p should be:
-------------------------------------
Code:
  CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS"
   (    "ID" NUMBER(8,0) NOT NULL ENABLE,
    "USER_ID" VARCHAR2(10) NOT NULL ENABLE,
    "USER_NAME" VARCHAR2(50),
    "TEAM" NUMBER(8,0) NOT NULL ENABLE,
    "ROLE" NUMBER(8,0) NOT NULL ENABLE,
    "TITLE" VARCHAR2(50),
    "TEAM_MANAGER" VARCHAR2(50),
    "COMPUTER_NAME" VARCHAR2(50),
     CONSTRAINT "PK_LKP11" PRIMARY KEY ("ID")
  TABLESPACE "TBSSCHEMA101"  ENABLE,
     CONSTRAINT "UQ_LKP11_USER_ID" UNIQUE ("USER_ID")
  TABLESPACE "TBSSCHEMA101"  ENABLE
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA102"

  CREATE TABLE "SCHEMA1"."LKP07_CHECK_PAYMENT_PLAN"
   (    "PAYMENT_PLAN" VARCHAR2(3),
    "PMS_FLAG" VARCHAR2(1),
     CONSTRAINT "PK_PAYMENT_PLAN" PRIMARY KEY ("PAYMENT_PLAN")
  TABLESPACE "TBSSCHEMA102"  ENABLE
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "TBSSCHEMA102"

-------------------------------------

Thanks in advance.

regards,
SatyaSmilie

Last edited by Franklin52; 05-02-2013 at 07:59 AM.. Reason: Please use code tags
# 2  
Old 05-02-2013
try..

Code:
 
sed '/USING INDEX/,/)/d' filename

# 3  
Old 05-02-2013
Please use code tags

From what I do see, you remove all 4 lines from USING INDEX to )

This awk should do the job
Code:
awk 'BEGIN {p=1} /USING INDEX/ {p=0} /)/ {p=1;next} p' file

Edit: shorter version
Code:
awk '{p=1} /USING INDEX/,/)/ {p=0} p' file


Last edited by Jotne; 05-02-2013 at 08:21 AM..
# 4  
Old 05-03-2013
Thanks all for the reply. Both the options are working fine..

Cheers,
Satya Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate consecutive lines with specific string

Hello, I'm trying to remove the duplicate consecutive lines with specific string "WARNING". File.txt abc; WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 bcd; abc; 123 123 123 WARNING 1234 WARNING 2345 WARNING 2345 efgh; (6 Replies)
Discussion started by: Mannu2525
6 Replies

2. Linux

How to remove lines without a particular string in either column?

I have a file that looks like this: DIP-27772N DIP-18408N refseq:NP_523941 DIP-23436N|refseq:NP_536784 DIP-23130N|refseq:NP_652017 DIP-22958N|refseq:NP_651195 DIP-20072N|refseq:NP_724597 DIP-22928N|refseq:NP_569972 DIP-22042N|refseq:NP_536744|uniprotkb:P54622... (4 Replies)
Discussion started by: Syeda Sumayya
4 Replies

3. Shell Programming and Scripting

Replace a string with multiple lines

Hello Guys, I need to replace a string with multiple lines. For eg:- ABC,DEF,GHI,JKL,MNO,PQR,STU need to convert the above as below:- ABC,DEF, GHI1 GHI2 GHI3, JKL,MNO, PQR1 PQR2 PQR3, STU i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies

4. UNIX for Dummies Questions & Answers

Remove lines in a positional file based on string value

Gurus, I am relatively new to Unix scripting and am struck with a problem in my script. I have positional input file which has a FLAG indicator in at position 11 in every record of the file. If the Flag has value =Y, then the record from the input needs to be written to a new file.However if... (3 Replies)
Discussion started by: gsam
3 Replies

5. UNIX for Dummies Questions & Answers

Remove lines contain certain string

i have file input aa,20120626 bb,45Cexpect to remove all lines when $2 doesn't end with 'C" output bb,45Ci tried this sed -i -nl -e '/\<C\>/ {p;} ' file1 but the result : sed illegal option -i (5 Replies)
Discussion started by: radius
5 Replies

6. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

7. Shell Programming and Scripting

Remove lines that match string at end of column

I have this: 301205 0000030000041.49000000.00 2011111815505 908 301205 0000020000029.10000000.00 2011111815505 962 301205 0000010000027.56000000.00 2011111815505 3083 312291 ... (2 Replies)
Discussion started by: herot
2 Replies

8. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

9. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

10. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies
Login or Register to Ask a Question