ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
here i want to replace server name from gIntegraHost to gTestRunHost but only between <TCPSampler and curl but after firing the below command only first instance is getting replaced not the other one.
sed '1,/<TCPSampler/!{ /curl.*END/,/<TCPSampler/!s/{gIntegraHost}/{gTestRunHost}/; }' file1 >aaa
Please edit your post and and surround the content of the file with the CODE tags making it ending with [/CODE] and beginning with [CODE] to make it easier to read.
Last edited by Didier Spaier; 06-15-2012 at 03:04 AM.
I want gIntegraHost to be replaced with gTestRunHost only where there in curl between<TCPSampler and </TCPSampler>. In below case it should not get replaced
<TCPSampler guiclass="TCPSamplerGui" testclass="TCPSampler" testname="Date" enabled="true">
<stringProp name="TestPlan.comments">This will clear any existing content in the webdav cache</stringProp>
<stringProp name="TCPSampler.server">${gIntegraHost}</stringProp>
<boolProp name="TCPSampler.reUseConnection">false</boolProp>
<stringProp name="TCPSampler.port">${gTcpShellPort}</stringProp>
<boolProp name="TCPSampler.nodelay">false</boolProp>
<stringProp name="TCPSampler.timeout"></stringProp>
<stringProp name="TCPSampler.request">date
END
</stringProp>
<stringProp name="ConfigTestElement.username"></stringProp>
<stringProp name="ConfigTestElement.password"></stringProp>
</TCPSampler>
sed '/<TCPSampler/{:a;N;/<\/TCPSampler/!ba; /curl/s/{gIntegraHost}/{gTestRunHost}/g}' input_file
The logic is as follows: collect all lines between '<TCPSampler' and '</TCPSampler' in the pattern space; after that if there is 'curl' in pattern space, then perform substitution globally (note the `g' flag).
Yes, it works for me. Please copy-paste corresponding text from terminal here, I'm just curious what's wrong. Also post input data using the [CODE]..[/CODE] tags to preserve formatting.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.