Programming :: Find And Replace Multiple Instances?
Aug 13, 2010
I have a file with the following in it:
:0 local /usr/X11R6/bin/X -nobanner
:1 local /usr/X11R6/bin/X
I need to add "-nolisten tcp" to both of these lines and cannot figure out how to do it. I can get it to do the first one, but not the 2nd and so on. How do I search the file and loop though it to change them all?
I have a line of text with multiple web links in the line. I'd like to replace the actual links with the text "<web-link>" so I don't accidentally hit them while reading on my iphone. I've tried many versions of the following sed command, sed 's/(http.*)/<web_link>/g', but it simply replaces everything between the first instance of "(http" and the last instance of ")" with <web_link>, or does nothing at all.
Ex: This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website. $ echo "This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website." | sed 's/(http.*)/<web_link>/g'
What I get is: This line has a link to a web page <web_link> to a website. What I'd like is: This line has a link to a web page <web_link> then some more text (extra text) and then another link <web_link> to a website. What am I doing wrong with my sed command?
It is possible to run multiple instances of a jar executable. Is it possible that only a single instance of the jar runs? Wrappers like JSmooth or Launch4J can be made to run as a single instance. But since there are no such wrappers for linux, I need a way to restrict the jar to a single instance. How to embed the jar file into an executable such it runs a single instance?
I am running a script that can run as many as 10 simultaneous times. During my testing, i noticed that if the script starts while another is in process, it inherits the $1 variable, which is always different.For example, the script starts with "scripthere.sh entry1", anther one starts almsot at the same time "scripthere.sh entry2". As the script is running, the second instance inherits $1 from the first script. So instead of $1 entry2, it shows up as entry1. how I can store $1 so that its unique to that instance of the script only?
I'm using Probe to monitor Tomcat5. The problem is that I've multiple instances of Tomcat.Can be used Probe to monitor multiples instances of Tomcat without having to deploy it to each instance?
After hours (literally) of searching the web and reading man pages, I think I've come up with the following:Code:find . -exec grep 'path/to/file' -print | xargs -0 -I new_path mv {this is where I get confused}So my code above is incomplete, obviously. In order to finish replacing the string, I need to mv the new file into the old file's spot. How do I do this, by incorporating it into my line of code?
I'm pretty sure this is doable from the command line, but my CLI skills have degraded a lot since my pre-Y2K admin days. The goal is to search all the files in the directory for a very long string of text and replace it with another string of text. The text being searched for is my Google Adsense code (which will be stripped from my website) and it will be replaced with a placeholder so I can easily tack something else in there in the future.
Seeing how I have that long snip of code on about 100 pages, automating the process would make life easier. If I was searching for a single word, I can see ways to do this. If I paste the code I'm searching for into a text file, is there a way to: find (contents of oldstring.txt) and replace with (contents of newstring.txt)?
I want to change some HTML in my files (80+ so I prefer not to do this by hand). I got a script to replace a string in files, however the HTML I want to replace contains an enter (and tab of 4 spaces) (explanation below) Does someone know how I could update my HTML by using a function in Linux?
I also found sed but don't know how to use it with the enter (linenumbers will not work because they variate)...
Im looking for assistance to create a script to find and replace files.Probably best if I give you the background Our server uses a specific application which stores user data, each user data account (a folder on the server) has a file called 'Profile.xml' this file gets updated and replaced about every 30 mins similar to the fashion logrotate works i.e. Profile.xml.1 Profile.xml.2 -> .10
What we experience is that if the application crashes unexpectedly while it is doing its user profile refresh task we end up with sometimes a few hundred Profile.xml files which end up 0kb(should be around 4kb) , and our server see's these as corrupted profiles and will not see them. Our fix is to go back thru and rename the Profile.xml.1 to be Profile.xml (or sometimes up to Profile.xml.5 to Profile.xml) We want a script we can manually run to automate this process The server tree is
When I grep kernel.exec-shield I get both line, hence I keep over writing the kernel.exec-shield-randomize in my script because it finds them both for my sed commend.
How can I get an exact match with either sed/awk/grep in shell so I can do a find and replace?
Example: sed 's/^kernel.exec-shield =.*/kernel.exec-shield = 1/g' /etc/sysctl.conf will replace BOTH lines
Example: grep "^kernel.exec-shield" find both line and I want it to find only the exact line.
I would like to have a script that will do a search in an XML file for a specific block of XML code and replace it with a different block of XML code using the Windows build of GNU Sed 4.1.5.
Here's the text I want to find:
Code:
And here's what I want to replace it with:
Code:
There is however a lot of stuff in there that would mess up sed, and the one example from the sed FAQ (from the Sourceforge site) that looked promising and easy enough to figure out (4.23.3. Try to use a block of "literal strings") fails with this error message: sed: file blockrep.sed line 18: unterminated `s' command
Anyone got any ideas, or even an alternate program that can do this? (Preferably one that I can automate.)
I'm writing a program in Python that presents a place for the user to input one-line of text (using raw_input). I need, however, as the user types, for certain words to be replaced, even before the user hits enter.
I try to make an animation so you can see what I mean, here the word "pig" gets replaced with "sheep": >I| >I | >I l| >I li| >I lik| >I like| >I like | >I like t| >I like to| >I like to | >I like to e| >I like to ea| >I like to eat| >I like to eat | >I like to eat p| >I like to eat pi| >I like to eat pig| >I like to eat sheep|
Note, the user never typed "sheep", the program replaced "pig" with "sheep" as soon as they finished typing the word "pig". The user did not use "Enter". Is this at all possible in Python?
I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile where as $findstring = print F_WC_TMP"$line "; and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line ";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
I have multiple hard drives with videos on them and i can only get the my xbox to read the 1st in my list of directories. So i wanted to know can i run multiple instances of ushare and use one for each hard drive? Is it possible?
In windows xp, i created another user account. Now i can run a second instance of any program by right clicking on it and selecting Run as. Is such a thing possible in linux (centos or ubuntu) in graphical environment ?
i'm new to linux, and i want to create mumble servers for my friends.My first server is finished and he works but, is it possible to create multiples instances of mumble ?
I've got two sound cards fitted, before I've always killed pulseaudio as a pain in the butt.
Without pulseaudio enabled I could run two audio apps simultaneously, ie run a SDR ( software defined radio) app , and listen to music or watch TV at the same time.
However, with puls audio running, you can only run one, either input to either output. So can a second instance of pulseaudio be run, master and slave perhaps ?
How can I have multiple independent instances of Mozilla Firefox 3.5 on the same X server, but started from different user accounts (consequently, different profiles)?
Limited success was only with Xephyr :1, DISPLAY=:1 /usr/local/bin/firefox, but Xephyr has no Cygwin/X's "rootless" mode so it's not comfortable (see other question).
The idea is to have one Firefox instance for various "Serious Business" things and the other for regular browsing with dozens of add-ons securely isolated.
On Windows If I run Firefox as user jack, and then try to start another instance of firefox I will be unable to, as one is already running.If I choose to run firefox as administrator,then I can have two instances of firefox, separate from each other side by side, because they are under different user accounts.This does not seem to be true on Linux.As user jack if I start firefox, like on windows I am unable to start a new instance.If I open a terminal and change to root, set XAUTHORITY to jacks .Xauthority and try to start firefox as root....I get the error that firefox is already running.
The great clock applet shows tasks and appointments from the evolution calendar. That's a great and fast overview of my agenda. But clicking a task of appointment opens a new instance from evolution every time, which is enormously annoying and really destroying productivity. I don't want 15 calendars open, I want the applet to behave like an index. So it should reuse the open instance and bring focus to the clicked appointment or task. How do I disable multiple instances of evolution?
I have a test server on which I'd like to run up to 30 separate instances of a program as daemons, each running on a different IP address bound to the server. I've created a init script that takes an additional command line parameter - the last octet of the IP address. For example:
Code:
sudo myprog 40 start sudo myprog 41 start
This would run instances of the program on IP addresses 192.168.1.40 and 192.168.1.41 respectively. But it's looking like this approach isn't doable if I wish to have any or all of these run at startup, as the links in the rcN.d directories can only link to the init script, not pass a parameter.
I tried the google and browsing the known bugs in the sticky before posting this thread.On boot the machine is pegged at 100%. It is a dual-core with 4GB of ram and is running 10.04, 64bit. Also, as time goes on it eats up all the ram till theres maybe 32mb free. What happens is there are multiple 4-10+ identical processes running. seem to be gnome related.The machine sits idle on my floor and runs samba and apache/mysql/gallery for my test website that no on but myself visits.
I have enabled netbook-launcher-efl and like the interface quite a lot, but it only allows me to launch a single instance of each application. I was told in an unrelated thread that there should be a setting in gconf-editor that enables multiple instances to be launched, but I thought it would be more appropriate if I broke that out into a separate thread.