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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reformatting a file - best way?

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
0
0
GB
I have a file which can be of a variable length and with limited structure. In fact, it is a trace file from an Oracle 9i DB.

Here is the file in its entirity (-top- and -bottom- added by me):
-top-
Dump file /oracle/app/oracle/admin/IFST/udump/ifst_ora_27660.trc
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
ORACLE_HOME = /oracle/app/oracle/product/9.2.0.1.0
System name: AIX
Node name: IFSSERVER
Release: 1
Version: 5
Machine: 005D87BA4C00
Instance name: IFST
Redo thread mounted by this instance: 1
Oracle process number: 31
Unix process pid: 27660, image: oracle@IFSSERVER (TNS V1-V3)

*** SESSION ID:(28.6513) 2003-09-15 10:35:50.413
*** 2003-09-15 10:35:50.413
# The following are current System-scope REDO Log Archival related
# parameters and can be included in the database initialization file.
#
# LOG_ARCHIVE_DEST=''
# LOG_ARCHIVE_DUPLEX_DEST=''
#
# LOG_ARCHIVE_FORMAT=%t_%s.dbf
# REMOTE_ARCHIVE_ENABLE=TRUE
# LOG_ARCHIVE_MAX_PROCESSES=2
# STANDBY_FILE_MANAGEMENT=MANUAL
# STANDBY_ARCHIVE_DEST=?/dbs/arch
# FAL_CLIENT=''
# FAL_SERVER=''
#
# LOG_ARCHIVE_DEST_1='LOCATION=/oracle/app/oracle/product/9.2.0.1.0/dbs/arch'
# LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
# LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM SYNC'
# LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
# LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED'
# LOG_ARCHIVE_DEST_STATE_1=ENABLE
#
# Below are two sets of SQL statements, each of which creates a new
# control file and uses it to open the database. The first set opens
# the database with the NORESETLOGS option and should be used only if
# the current versions of all online logs are available. The second
# set opens the database with the RESETLOGS option and should be used
# if online logs are unavailable.
# The appropriate set of statements can be copied from the trace into
# a script file, edited as necessary, and executed when there is a
# need to re-create the control file.
#
# Set #1. NORESETLOGS case
#
# The following commands will create a new control file and use it
# to open the database.
# Data used by the recovery manager will be lost. Additional logs may
# be required for media recovery of offline data files. Use this
# only if the current version of all online logs are available.
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "IFST" NORESETLOGS NOARCHIVELOG
-- SET STANDBY TO MAXIMIZE PERFORMANCE
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 254
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 (
'/redolog1/IFST/redo01.log',
'/redolog2/IFST/redo01a.log'
) SIZE 50M,
GROUP 2 (
'/redolog1/IFST/redo02.log',
'/redolog2/IFST/redo02a.log'
) SIZE 50M,
GROUP 3 (
'/redolog1/IFST/redo03.log',
'/redolog2/IFST/redo03a.log'
) SIZE 50M,
GROUP 4 (
'/redolog1/IFST/redo04.log',
'/redolog2/IFST/redo04a.log'
) SIZE 50M,
GROUP 5 (
'/redolog1/IFST/redo05.log',
'/redolog2/IFST/redo05a.log'
) SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/redolog1/IFST/system01.dbf',
'/redolog2/IFST/undotbs01.dbf',
'/oracleindex/IFST/users01.dbf',
'/oracledata/IFST/ifsapp_data01.dbf',
'/oracleindex/IFST/ifsapp_index01.dbf',
'/oracledata/IFST/ifsapp_report_data01.dbf',
'/oracleindex/IFST/ifsapp_report_index01.dbf',
'/oracledata/IFST/ifsapp_archive_data01.dbf',
'/oracleindex/IFST/ifsapp_archive_index01.dbf'
CHARACTER SET WE8MSWIN1252
;
# Recovery is required if any of the datafiles are restored backups,
# or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;
# Commands to add tempfiles to temporary tablespaces.
# Online tempfiles have complete space information.
# Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/oracledata/IFST/temp01.dbf'
SIZE 524288000 REUSE AUTOEXTEND OFF;
# End of tempfile additions.
#
# Set #2. RESETLOGS case
#
# The following commands will create a new control file and use it
# to open the database.
# The contents of online logs will be lost and all backups will
# be invalidated. Use this only if online logs are damaged.
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "IFST" RESETLOGS NOARCHIVELOG
-- SET STANDBY TO MAXIMIZE PERFORMANCE
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 254
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 (
'/redolog1/IFST/redo01.log',
'/redolog2/IFST/redo01a.log'
) SIZE 50M,
GROUP 2 (
'/redolog1/IFST/redo02.log',
'/redolog2/IFST/redo02a.log'
) SIZE 50M,
GROUP 3 (
'/redolog1/IFST/redo03.log',
'/redolog2/IFST/redo03a.log'
) SIZE 50M,
GROUP 4 (
'/redolog1/IFST/redo04.log',
'/redolog2/IFST/redo04a.log'
) SIZE 50M,
GROUP 5 (
'/redolog1/IFST/redo05.log',
'/redolog2/IFST/redo05a.log'
) SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/redolog1/IFST/system01.dbf',
'/redolog2/IFST/undotbs01.dbf',
'/oracleindex/IFST/users01.dbf',
'/oracledata/IFST/ifsapp_data01.dbf',
'/oracleindex/IFST/ifsapp_index01.dbf',
'/oracledata/IFST/ifsapp_report_data01.dbf',
'/oracleindex/IFST/ifsapp_report_index01.dbf',
'/oracledata/IFST/ifsapp_archive_data01.dbf',
'/oracleindex/IFST/ifsapp_archive_index01.dbf'
CHARACTER SET WE8MSWIN1252
;
# Recovery is required if any of the datafiles are restored backups,
# or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
# Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
# Commands to add tempfiles to temporary tablespaces.
# Online tempfiles have complete space information.
# Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/oracledata/IFST/temp01.dbf'
SIZE 524288000 REUSE AUTOEXTEND OFF;
# End of tempfile additions.
#
-bottom-


From that file, I want to produce this:
-top-
STARTUP NOMOUNT pfile=/oracle/app/oracle/admin/IFSD/pfile/initIFSD.ora
CREATE CONTROLFILE SET DATABASE "IFSD" RESETLOGS NOARCHIVELOG
-- SET STANDBY TO MAXIMIZE PERFORMANCE
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 254
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 (
'/redolog1/IFSD/redo01.log',
'/redolog2/IFSD/redo01a.log'
) SIZE 50M,
GROUP 2 (
'/redolog1/IFSD/redo02.log',
'/redolog2/IFSD/redo02a.log'
) SIZE 50M,
GROUP 3 (
'/redolog1/IFSD/redo03.log',
'/redolog2/IFSD/redo03a.log'
) SIZE 50M,
GROUP 4 (
'/redolog1/IFSD/redo04.log',
'/redolog2/IFSD/redo04a.log'
) SIZE 50M,
GROUP 5 (
'/redolog1/IFSD/redo05.log',
'/redolog2/IFSD/redo05a.log'
) SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/redolog1/IFSD/system01.dbf',
'/redolog2/IFSD/undotbs01.dbf',
'/oracleindex/IFSD/users01.dbf',
'/oracledata/IFSD/ifsapp_data01.dbf',
'/oracleindex/IFSD/ifsapp_index01.dbf',
'/oracledata/IFSD/ifsapp_report_data01.dbf',
'/oracleindex/IFSD/ifsapp_report_index01.dbf',
'/oracledata/IFSD/ifsapp_archive_data01.dbf',
'/oracleindex/IFSD/ifsapp_archive_index01.dbf'
CHARACTER SET WE8MSWIN1252
;
ALTER DATABASE OPEN RESETLOGS;
ALTER DATABASE RENAME GLOBAL_NAME TO IFSD;
-bottom-



which means deleting a lot of lines, adding a few and changing a few.

The idea is to allow me to refresh a test DB from a live one while keeping the script open enough (by running a modified control file) to not worry if teh source DB has expanded (ie extra dbfs)

I know I can sed /#/d to remove all lines with #.
I know I have to s/sourcedb/destdb to rename DB.

But how do I say delete every line up to but not including the second START NOMOUNT ?

Many thanks for any help!




 
A little script like this (not exactly elegant) will do the trick.

USAGE: script_name <oldfile> <newfile>

#/bin/ksh
rm -f $2
startup_count=0
while read line
do
wrk1=`echo $line | grep ^STARTUP | cut -d&quot; &quot; -f1`
if [ &quot;$wrk1&quot; = &quot;STARTUP&quot; ]
then
let startup_count=startup_count+1
fi
if [ &quot;$startup_count&quot; -gt 1 ]
then
echo &quot;$line&quot; >> $2
else
continue
fi
done < $1


LHLTech

IBM Certified ATE
 
Thats great, thanks. Can you advise how I can take this further? Within that script, to cease output after the ; (to lose the final lines) ?
 
I managed to do it, on my tod.

#/bin/ksh
rm -f $2
startup_count=0
while read line
do
wrk1=`echo $line | grep ^STARTUP | cut -d&quot; &quot; -f1`
if [ &quot;$wrk1&quot; = &quot;STARTUP&quot; ]
then
let startup_count=startup_count+1
fi

if [[ &quot;$line&quot; = &quot;;&quot; ]] && [[ &quot;$startup_count&quot; -gt 1 ]]
then
echo &quot;;&quot; >> $2
exit 0
fi

if [ &quot;$startup_count&quot; -gt 1 ]
then
echo &quot;$line&quot; >> $2
else
continue
fi
done < $1

exit 0


 
that script is pretty nice but i never saw a need to do that. using vi i just do '/^CREA' to find the first line to modify. i change it apropriately and delete everything above it using 'd1G' (or 'dgg' in vim). then i '/RESETLOGS' and 'dG' to clip the bottom. basically, the part of the file i am interested in lies in the middle.

IBM Certified -- AIX 4.3 Obfuscation
 
Yegolev: But that's a manual method, isn't it? I needed to do this in a script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top