Sponsored Content
Top Forums Shell Programming and Scripting Problem while replacing text between two tags Post 302656271 by abhitanshu on Thursday 14th of June 2012 11:47:06 AM
Old 06-14-2012
I am using Red hat Linux 6.2.

Sample Input is -
Code:
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <stringProp name="TCPSampler.port">${gTcpShellPort}</stringProp>
END
</stringProp>
          </TCPSampler>
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <boolProp name="TCPSampler.reUseConnection">false</boolProp>
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort} http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma: no-cache&quot; --range 500000-1000000 -A &quot;${lUserAgent}&quot; -o resp.data
END
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">date
END
</stringProp>
            <stringProp name="ConfigTestElement.username"></stringProp>
          </TCPSampler>
          <hashTree/>
          <TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Curl Request 1" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">cd /tmp
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort} http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma: no-cache&quot; --range 500000-1000000 -A &quot;${lUserAgent}&quot; -o resp.data
END<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <stringProp name="TCPSampler.port">${gTcpShellPort}</stringProp>
            <stringProp name="TCPSampler.timeout"></stringProp>
            <stringProp name="TCPSampler.request">date
END
</stringProp>
            <stringProp name="ConfigTestElement.username"></stringProp>
            <stringProp name="ConfigTestElement.password"></stringProp>
          </TCPSampler>
          <hashTree/>
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Curl Request 1" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">cd /tmp
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort} http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma: no-cache&quot; --range 500000-1000000 -A &quot;${lUserAgent}&quot; -o resp.data
END


and Sample output should be -

Code:
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <stringProp name="TCPSampler.port">${gTcpShellPort}</stringProp>
END
</stringProp>
          </TCPSampler>
            <stringProp name="TCPSampler.server">${gTestRunHost}</stringProp>
            <boolProp name="TCPSampler.reUseConnection">false</boolProp>
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort}  http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma:  no-cache&quot; --range 500000-1000000 -A  &quot;${lUserAgent}&quot; -o resp.data
END
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">date
END
</stringProp>
            <stringProp name="ConfigTestElement.username"></stringProp>
          </TCPSampler>
          <hashTree/>
          <TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Curl Request 1" enabled="true">
            <stringProp name="TCPSampler.server">${gTestRunHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">cd /tmp
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort}  http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma:  no-cache&quot; --range 500000-1000000 -A  &quot;${lUserAgent}&quot; -o resp.data
END<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Req Request" enabled="true">
            <stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
            <stringProp name="TCPSampler.port">${gTcpShellPort}</stringProp>
            <stringProp name="TCPSampler.timeout"></stringProp>
            <stringProp name="TCPSampler.request">date
END
</stringProp>
            <stringProp name="ConfigTestElement.username"></stringProp>
            <stringProp name="ConfigTestElement.password"></stringProp>
          </TCPSampler>
          <hashTree/>
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Curl Request 1" enabled="true">
            <stringProp name="TCPSampler.server">${gTestRunHost}</stringProp>
            <boolProp name="TCPSampler.nodelay">false</boolProp>
            <stringProp name="TCPSampler.request">cd /tmp
rm -f resp.data
curl -v -x ${gIntegraHost}:${gIntegraPort}  http://${gTestOSHost}${gTestOSPath}video01.mp4 -H &quot;Pragma:  no-cache&quot; --range 500000-1000000 -A  &quot;${lUserAgent}&quot; -o resp.data
END

and i am using below command -

Code:
sed '1,/<TCPSampler/!{ /curl/,/<TCPSampler/!s/{gIntegraHost}/{gTestRunHost}/; }' file1

---------- Post updated at 10:47 AM ---------- Previous update was at 10:39 AM ----------

I have pasted my desired output in previous post.

I am getting gIntegraHost replaced with gTestRunHost only at the first instance with my command not the other 2.

Last edited by Corona688; 06-14-2012 at 12:44 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing text

hey how can i change part of a file i hve to do in a masses so mv or cp is not practical. I have to change xxx_rrr to xxx_yyy pls help thank (2 Replies)
Discussion started by: ajaya
2 Replies

2. Shell Programming and Scripting

Replacing text

I was using the following code to replace the path names and it works when it is echo "$PWD/$f" | sed -e 's/^.*chris\.domain\.com/chris.domain.com/' IN fact it works great However I tried to incorporate a variable echo "$PWD/$f" | sed -e... (3 Replies)
Discussion started by: chrchcol
3 Replies

3. Shell Programming and Scripting

help required for replacing text in vi

Hi Any one pls give me command in vi to replace /opt/usr with /home/reddy/dump .... i tried escaping / with \ bt its not working... thanks in advance (6 Replies)
Discussion started by: Chandu2u
6 Replies

4. Shell Programming and Scripting

Replacing Text in Text file

Hi Guys, I am needing some help writing a shell script to replace the following in a text file /opt/was/apps/was61 with some other path eg /usr/blan/blah/blah. I know that i can do it using sed or perl but just having difficulty writing the escape characters for it All Help... (3 Replies)
Discussion started by: cgilchrist
3 Replies

5. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

6. Shell Programming and Scripting

Matching and replacing text

Im new to using perl scripting, and i was wondering if anyone could help me, I need to create a cgi file that when it runs it opens a file looks through all the words, and replace the word hello with goodbye, ive been looking around and someone said to use an If statement, but ive found no other... (2 Replies)
Discussion started by: xzen123
2 Replies

7. Shell Programming and Scripting

In PHP replacing text between TAGS & URI information in Title Tag

Hi, what I am trying to do in PHP, is to replace the Title. I need some of the URL information inside aswell depending on the domain. The title is always different so I need to store it in a variable, put the url info like described below in front of it. Here is an example how it should... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. Shell Programming and Scripting

Replacing text between Tags, with output from a complex command

The Problem I have n files all named "conf.cfg", each of which contain a line that reads: "MyVar=XXX", where XXX can be any value. I have a second file called report.xml, that might read: <Reports> <Report>Report1</Report> <Report>Report2</Report> <Report>Report3</Report> </Reports> I... (1 Reply)
Discussion started by: Flang
1 Replies

9. Shell Programming and Scripting

Replacing text/characters in vi

ok, so i have the following text to replace but it's not working. can someone please help me out: :%s~awk '// {split($2,s,",");a=$1 FS s} /-/ {b=a} END{print b}'~tail -1~g I want to replace the entire awk command with tail -1. thanks (7 Replies)
Discussion started by: SkySmart
7 Replies

10. Shell Programming and Scripting

Replacing text on every third line

I have file like this "copy table_name from filea.txt on node replace delimiter '|';" "copy table_name from fileb.txt on node replace delimiter '|';" "copy table_name from filec.txt on node replace delimiter'|';" "copy table_name from filee.txt on node replace delimiter '|';" "copy... (1 Reply)
Discussion started by: nnani
1 Replies
All times are GMT -4. The time now is 09:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy