Replace 1 word after pattern match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace 1 word after pattern match
# 1  
Old 03-28-2009
Replace 1 word after pattern match

Hi,

Here is my pattern

Code:
CREATE USER LZ
  IDENTIFIED BY VALUES 'A0144280ESD70'
  DEFAULT TABLESPACE USERS
  TEMPORARY TABLESPACE TEMP1 PROFILE DEVELOPER_D_1
  ACCOUNT UNLOCK
/

The Sed command must look for the Line that contains TEMPORARY TABLESPACE and replace the immediate word (TEMP1 in this case) after pattern (TEMPORARY TABLESPACE in this case)

the above must be changed to

Code:
CREATE USER LZ
  IDENTIFIED BY VALUES 'A0144280ESD70'
  DEFAULT TABLESPACE USERS
  TEMPORARY TABLESPACE USERS PROFILE DEVELOPER_D_1
  ACCOUNT UNLOCK
/

I am trying with the below sed commands

Code:
sed '/TEMPORARY TABLESPACE.*/s/TEMPORARY TABLESPACE.* /TEMPORARY TABLESPACE USERS /g' 1.txt

The above one removes the word PROFILE which is not desired. Also as in this case the 3rd word after pattern is TEMP1 is not consisten it could be any 4 / 5 / 10 letter word.

Thanks,
Rajan.S
# 2  
Old 03-28-2009
Code:
sed 's/TEMPORARY TABLESPACE [^ ]+ /TEMPORARY TABLESPACE USERS /' 1.txt


Last edited by cfajohnson; 03-28-2009 at 02:01 PM..
# 3  
Old 03-28-2009
Nope it doesnt seem to be working.

Sed is not able to identify the pattern at all when i use

Code:
/TEMPORARY TABLESPACE [^ ]+ /

# 4  
Old 03-28-2009

Try:
Code:
sed 's/TEMPORARY TABLESPACE [^ ]\+ /TEMPORARY TABLESPACE USERS /' 1.txt

Or:
Code:
sed 's/TEMPORARY TABLESPACE [^ ]* /TEMPORARY TABLESPACE USERS /' 1.txt

(What version of sed are you using? Which shell?}
# 5  
Old 03-28-2009
Code:
sed 's/TEMPORARY TABLESPACE [^ ]* /TEMPORARY TABLESPACE USERS /' 1.txt

Works perfect .. Thanks a lot....

Last edited by vidyadhar85; 03-28-2009 at 05:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed script to delete the last word after a last pattern match

Hi Guys , I am having a file as stated below File 1 sa0 -- i_core/i_core_apb/i_afe0_controller/U261/A sa0 -- i_core/i_core_apb/i_afe0_controller/U265/Z sa1 -- i_core/i_core_apb/i_afe0_controller/U265/A sa1 -- i_core/i_core_apb/i_afe0_controller/U268/Z sa1 -- ... (7 Replies)
Discussion started by: kshitij
7 Replies

2. Shell Programming and Scripting

If pattern match, replace it with #

This command is not working for me. awk '{if ($1 == server) {$1 = #server} }' /etc/ntp.conf # grep server /etc/ntp.conf # Use public servers from the pool.ntp.org project. server 0.rhel.pool.ntp.org iburst server 1.rhel.pool.ntp.org iburst server 2.rhel.pool.ntp.org iburst server... (5 Replies)
Discussion started by: kenshinhimura
5 Replies

3. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

4. Shell Programming and Scripting

Help with Pattern match and replace

I have a file containing a multiple lines of the format sddfdsf_gaf/ywrtrtwrt_gaf ghfghfgh_ert/xcvxcvcv_ert werwerwwerw_adf/jkhjkhjkjhkjhk_adf I am interested in only the first 3 letters following the "_" character and make those 3 letters uppercase after extraction. So would like to convert... (5 Replies)
Discussion started by: inditopgun
5 Replies

5. Shell Programming and Scripting

pattern match and replace another pattern in same line

I have a pattern username:x:32005:32006::/usr/local/user:/bin/bash I need to match the line containing username and replace /bin/bash with /usr/local/my/bin/noshell So it becomes username:x:32005:32006::/usr/local/user:/usr/local/my/bin/noshell (7 Replies)
Discussion started by: anilcliff
7 Replies

6. Shell Programming and Scripting

replace pattern after the first pattern match

I need this. aaa OOOOO bbb ccc OOOOO ddd fff ggg OOOOO iii OOOOO I need all OOOOO replaced with PPPPP, but only change after the pattern ggg. So the first two OOOOO should not be changed. OUTPUT should be :- aaa (2 Replies)
Discussion started by: anilcliff
2 Replies

7. Shell Programming and Scripting

print word after pattern match in two instances

i have a file like below. how can i printout the digits followed by the pattern -bwout and -bwin. say i run the script by entering line number 145 (the fourth line), then the o/p should be like 5000000 1024000 8 test1 -ipprot erp -ppsout 500 -ppsin 500 -bwout 300000 -bwin 300000 -statsdevice... (7 Replies)
Discussion started by: sb245
7 Replies

8. Shell Programming and Scripting

Match pattern and replace with string

hi guys, insert into /*<new>*/abc_db.tbl_name this is should be replaced to insert into /*<new>*/${new}.tbl_name it should use '.' as delimiter and replace is there any way to do it using sed (6 Replies)
Discussion started by: sol_nov
6 Replies

9. Shell Programming and Scripting

Match pattern and replace

Hi All, I am new to unix shell scripting, I need your help guys in coming up with some thing for the following scenario: file1 ABC_BASE ${base} ABC_ACC ${acc} ABC_TEST ${test} 01-01-2006 ${from_dt} 01-15-2006 ${to_dt} file 2 I have an file2.sql file which contains: ####This... (4 Replies)
Discussion started by: sol_nov
4 Replies

10. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies
Login or Register to Ask a Question