Operating System - HP-UX
1748213 Members
3130 Online
108759 Solutions
New Discussion юеВ

change of a string in different lines

 
SOLVED
Go to solution
Billa-User
Regular Advisor

change of a string in different lines

hello,
i have a dynamic file, which is generated by an ORACLE tool. Now i want to change a string, which begins with TABLESPACE following by "Name of Tablespace". The name of the new TABLESPACE is static.

Example: TABLESPACE new : APPLI
old: TABLESPACE "AMITTEL"
new: TABLESPACE "APPLI"

this is easy but i have following situation:

REM 255 TABLESPACE "AMITTEL" LOGGING PARTITION BY RANGE ("FIRMA" ,
REM "BON_DATZT" ) (PARTITION "FA_00_WO_0ANF" VALUES LESS THAN ('00',
REM 255 STORAGE(INITIAL 262144 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE
REM "APPLI" LOGGING NOCOMPRESS, PARTITION "FA_00_WO_200801" VALUES LESS

i attach the whole file.
i don't know, how to change it over different lines ...

regards,tom
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: change of a string in different lines

Shalom,

I'd recommend making this into a script and make the tablespace name an input variable taken on the command line like $1

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor
Solution

Re: change of a string in different lines

Hi Tom:

Try this:

# perl -00 -pe 's/TABLESPACE "AMITTEL"/TABLESPACE "APPLI"/gms;s/(TABLESPACE\s*REM\s*)"AMITTEL"/$1"APPLI"/gms' file

...and if you want to update your "file" in-place, simply change '-pe' to '-pi.old -e' as:

# perl -00 -pi.old -e 's/TABLESPACE "AMITTEL"/TABLESPACE "APPLI"/gms;s/(TABLESPACE\s*REM\s*)"AMITTEL"/$1"APPLI"/gms' file

Regards!

...JRF...

Hein van den Heuvel
Honored Contributor

Re: change of a string in different lines

fwiw, I think specifying -0 suffices to make perl treat the file as a long big string and be ready for the replace accross new-lines:

# perl -0 -pe 's/TABLESPACE(\s+|\s*REM\s*)"\w+/TABLESPACE$1"appli/g' old.tmp > new.tmp

The "/m" for "Treat string as multiple lines." is not for this me thinks.

The critical part here is : (\s+|\s*REM\s*)
This matches with just whitespace OR whitespace surrounding REM and remimbers either in $1 to be used in the substitution.

But typically the tablespace name(s) between their double quotes are unique enough. If so the perl solution could just be:

perl -pe 's/"AGROSS"|"AMITTEL"|"APPLI"/"test"/' old .tmp > new.tmp

fwiw,
Hein.


Billa-User
Regular Advisor

Re: change of a string in different lines

hello,

thank your for perfect solutions: i choice one example and extented it like :

NEW_TBLSP="APPLIU"
echo $NEW_TBLSP
export NEW_TBLSP
perl -00 -pi.old -e 's/TABLESPACE "[A-Z]*"/TABLESPACE "$ENV{"NEW_TBLSP"}"/gms;s/(TABLESPACE\s*REM\s*)"[A-Z]*"/$1"$ENV{"NEW_TBLSP"}"/gms' file

it works perfect.

thank to all

Tom