Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit file to extract certain lines only - sed probably 1

Status
Not open for further replies.

kasparov

Programmer
Feb 13, 2002
203
GB
I want to automatically edit the file produced from an Oracle database by running this:
Code:
alter database backup controlfile to trace;
so that I only get the first definition of the control file - i.e. the first part that begins
Code:
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "OUT_DATABASE" NORESETLOGS  NOARCHIVELOG
    MAXLOGFILES 5
    MAXLOGMEMBERS 5
and ends
Code:
  '/our_database/indx03.dbf',
  '/our_database/indx04.dbf',
  '/our_database/cftest_LOB_TS.dbf',
  '/our_database/cftest_tools01.dbf'
CHARACTER SET WE8ISO8859P1
;

This section appears twice in the file (with small differences) and I only want the first occurrence. Both occurrences begin with 'STARTUP NOMOUNT' and end with ';'.

I've tried this (UUOC I know :))
Code:
cat control.sql | sed -n '/^STARTUP NOMOUNT/,/^;/p'
which gives me both occurrences (and correctly strips everything else out). But I don't know how to only get the first occurrence.

I can't be certain this will always be on the same lines so I can't print certain line numbers only. I could hack away at removing the 2nd occurrence of the lines but there must be a simpler way to do it.

Hope this makes sense to you all. Any advice appreciated as usual.

Thanks, Chris

 
Thanks for the reply feherke

Unfortunately I'm getting
Code:
sed: command garbled: /^STARTUP NOMOUNT/,/^;/{p;/q}
I'm on Solaris 10. What exactly should
Code:
{p;/^;/q}
do? I'm guessing it's:
p - print
/^;/q - don't print after the semi-colon

That's what I'm aiming for anyway.

Cheers, Chris
 
God bless the semi-colon :)

It works . Thanks you feherke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top