Search and replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and replace
# 1  
Old 09-15-2008
Bug Search and replace

Hi All,

Suppose I have a file "a.doc"

It's contents are :

mos44.0 )

.....
......
.....


export TKTS_RELEASE=tkts44.0b7
......
.......


Now , I need to first search for the pattern "mos44.0 )" and then TKTS_RELEASE will be some 30 lines below(not 30 always)...

I need to go there and then modify the value of TKTS_RELEASE variable from tkts44.0b7 to tkts44.0b10.

For modifying the contents I can use sed command ...But how do I determine where the changes shud be done...The place where I change shud satisfy two conditions ...1) "mos44.0 )" and then some lines below..TKTS_RELEASE variable..

Kindly advice...Thanking in advance....
# 2  
Old 09-15-2008
You may try this:
Code:
grep -q "mos44.0" file_name && sed 's/tkts44.0b7/tkts44.0b10/' file_name

# 3  
Old 09-15-2008
Can you show a bit more of this file please? Is "mos44.0 )" a kind of label that marks the start of a section? Is there anything else marking a kind of end of that section ie. when replacement should be stopped/not done?
# 4  
Old 09-15-2008
This should replace the first match of "tkts44.0b7" after "mos44.0"

Code:
awk '
/mos44.0/{f=1}
/TKTS_RELEASE=/ && f {sub("tkts44.0b7","tkts44.0b10");f=0}
{print}' file > newfile

Regards
# 5  
Old 09-15-2008
Franklin,
Thanks a lot for your response...

I ran the command but I get this error

awk '/mos44.0/{f=1}/TKTS_RELEASE=/ && f {sub("tkts44.0b7",tkts44.0b10");f=0} {print}' bmp.config > bmp1.config
awk: syntax error near line 1
awk: bailing out near line 1
# 6  
Old 09-15-2008
zaxxon,
FInd the file

6194 mos44.0 )

6195 prepath PATH /scme/lbin /opt/SUNWspro/bin /opt/nmake3.1.
2/bin /usr/ccs/bin/usr/add-on/unison/bin
6196 addpath PATH /opt/quantify
6197 addpath MANPATH /opt/quantify/man /opt/purify/man



6221 export DSS_RELEASE=dss11.0b1
6222 export MOS_RELEASE=mos44.0b1
6223 export TSTS_RELEASE=tsts41.0b1
6224 export COM_RELEASE=com33.0b1
6225 export TKTS_RELEASE=tkts44.0b7
6226 export CCPLITE_RELEASE=ccplite1.0
6227 export TKES_RELEASE=tkes11.0b8

mos44.0 ) (mos44.0 followed by a closing bracket ) in line 6194 of the file

then TKTS_RELEASE variable in line 6225...

Need to modify this TKTS_RELAESE variable to tkts44.0b10.

TKTS_RELEASE variable will be at several places ..but I need to modify this variable only after some lines from mos44.0.
# 7  
Old 09-15-2008
Quote:
Originally Posted by sanyerra
Franklin,
Thanks a lot for your response...

I ran the command but I get this error

awk '/mos44.0/{f=1}/TKTS_RELEASE=/ && f {sub("tkts44.0b7",tkts44.0b10");f=0} {print}' bmp.config > bmp1.config
awk: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

2. Shell Programming and Scripting

Vi search and replace

Hi, I need help with search and replace for the following string using vi .. if ];then to if ];then can this be done in one search and replace or need multiple ? Thanks (3 Replies)
Discussion started by: talashil
3 Replies

3. UNIX for Dummies Questions & Answers

Help with search and replace or search only of / in vi

Hi all, I am editing a config file in vi that has a / on it. At the moment, search and replace looks alright as am able to use a # as a temporary separator, i.e. :,$s#/u01/app#/u02/app#g For doing a search, I have to escape the / do. So if I want to search for /u01/app, I am having to do... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. UNIX for Dummies Questions & Answers

Search and Replace

I am trying to search and replace using two different files with strict search rules. One file contain some data and the other file contain some numbers as shown below. DataFile.txt >L1_T1 text data... text data.. >L1_T1 text data... text data.. >L1_T1 text data... text data.. ........ (4 Replies)
Discussion started by: Fahmida
4 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

Search and Replace

Hi!!! I have following xml file with 3 sections. aaa1bbb-ccc default aaa1bbbdd default 0 11 23 * * aaa2bbb-ccc default aaa2bbbdd default 0 11 23 * * aaa3bbb-ccc default aaa3bbbdd default 0 15 23 * * (15 Replies)
Discussion started by: tdev457
15 Replies

7. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

8. Shell Programming and Scripting

Search and replace

I have a script which has several occurences of statement like command: $UCMDPATH/xyz abc I would like to replace the entire line starting from $UCMDPATH with the ls -ltr command eg: Prior to change:: command: $UCMDPATH/xyz abc After change: command: ls -ltr Is there a way to do... (12 Replies)
Discussion started by: jobbyjoseph
12 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

search and replace

hi all, the problem is like this...... i setup a file (Env.txt) which handles all the values. NAME1=xxxxxx, where xxxxx is the value NAME2=xxxxxx GGGGG=uusufu I have 6 files, where i will append the values from env.txt. These files has no specific format. all i want is to append the... (1 Reply)
Discussion started by: tungaw2004
1 Replies
Login or Register to Ask a Question