change of a string in different lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change of a string in different lines
# 1  
Old 09-03-2008
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
# 2  
Old 09-03-2008
Please be more clear on what you're asking for. I looked at your file, and it doesn't contain the value AMMITAL anywhere. So it seems you've already replaced it successfully.

I must not be understanding what you're asking, or you've attached the wrong file.
# 3  
Old 09-03-2008
Quote:
Originally Posted by bora99
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

I guess its a typo that you mention to replace AMITTEL as there is only APPLI in the sample file.


Please try the below code:


Code:
sed 's/APPLI/AMITTEL/g' filename >modified_file

or

Code:
perl -ne 's/APPLI/AMITTEL/g; print; ' filename

# 4  
Old 09-04-2008
hello,

i want to change all entries of TABLESPACE "*":

i have a string, which occurs in one line like :
REM 255 TABLESPACE "AMITTEL" LOGGING PARTITION BY RANGE ("FIRMA" ,

then i also i have a string, which occurs in different lines like:
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 L

i think , the first way is to change "REM " (with sed ) but then i want to
change all entries with TABLESPACE "*" through TABLESPACE "XX"

regards,tom
# 5  
Old 09-04-2008
Solutions

I got an solutions of experts:

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

or

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

or

# perl -0 -pe 's/TABLESPACE(\s+|\s*REM\s*)"\w+/TABLESPACE$1"appli/g' old.tmp > new.tmp
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

2. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

3. Shell Programming and Scripting

Inserting blank lines after string change

My input data looks like this ... -150 120 8 -150 122 7 -150 124 11 -150 126 8 -150 128 19 -150 130 13 -150 132 26 -150 134 38 -150 136 45 -150 138 62 -150 140 75 -150 142 110 -150 144 139 -150 146 138 -150 148 158 -150 150 173 -150 152 217 (5 Replies)
Discussion started by: chrisjorg
5 Replies

4. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

5. 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

6. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

7. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

8. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

9. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

10. Shell Programming and Scripting

[Perl] Find one string, change another string.

Hi, In principle I am searching for a Perl equivalent for this sed command: sed "/TIM_AM_ARGS=/ s/60/1440/" $EDIT_FILE > $TEMP_FILE cp $TEMP_FILE $EDIT_FILE I was wondering if it needs to be like this, or that there other, shorter, alternatives: open (TIMENVFILE, "<$timenvfile") or die... (5 Replies)
Discussion started by: ejdv
5 Replies
Login or Register to Ask a Question