search-and-replace

How to pass long strings for search and replace in a bash, sed, or rpl script?

I am working to create a script which will take a string as an argument and replace recursively in a directory. The simple case (a single word) is admirably handled by the following find and replace script: grep -rl $1 . | xargs sed -i .backup -e "s/$1/$2/g" But here things get a bit more tricky. The string I am trying to deal with...

Tool to replace include with its own contents?

I'm faced with the task of find and replacing multiple include files with the include file's content. Just wondering if I'd be quicker copy / pasting than writing a bit of code to do so, or if there's a tool out there that could do this for me? Pretty sure its a common need. I'm on Windoze btw. Any suggestions welcome. Just to clarif...

How can you remove one line which contains the word SID in many files?

How can you remove one line which contains the word SID in many files? I wondering between sed and tr. However, neither of them seem to work for the purpose. I also would like to have some flexibility because of the following reason. The problem is actually slightly more challenging. I need to remove also one line after the match in so...

Vim replace preVARIABLETEXTpost with VARIABLETEXT?

Using Vim, I'd like to be able to replace preVARIABLETEXTpost with VARIABLETEXT in a single command. The reason is that pre and post might exist elsewhere in the file, and VARIABLETEXT changes. Something like: :%s/preGRABTEXTpost/GRABTEXT/g Essentially I'm trying to strip pre and post when it exists with some text between them on ...

Replacing in the selected blocks of text end of line characters to spaces.

I have text file: gvim file.txt In UNIX you can type this at any command prompt. If you are running Microsoft Windows, open an MS-DOS prompt window and enter the command. In either case, Vim starts editing a file called file.txt. Because this is a new file, you get a blank window. This is what your screen will look like: ...

find keyword in particular div only rather then whole document

hi i want to find and replace functionality in contentEditable div.i want to add one toolbar in which one find and replace button placed. when one press this button then one popup window open and ask for keyword to search when keyword is given then it will find only in given div id not whole document and highlight it. if any body know ab...

Eclipse, regular expression search and replace

In eclipse, is it possible to use the matched search string as part of the replace string when performing a regular expression search and replace? Basically, I want to replace all occurrences of variableName.someMethod() with: ((TypeName)variableName.someMethod()) Where variableName can be any variable name at all. In sed I could...

How to use rake to insert/replace html section in each file?

I'm using rake to create a Table of contents from a bunch of static HTML files. The question is how do I insert it into all files from within rake? I have a <ul id="toc"> in each file to aim for. The entire content of that I want to replace. I was thinking about using Nokogiri or similar to parse the document and replace the DOM node...

Using vi, how can I make CSS rules into one liners?

Example bad: #main { padding:0; margin: 10px auto; } Example good: #main {padding:0;margin:10px auto;} I have a ton of CSS rules that are taking up too many lines. And I cannot figure out the :%s/ commands to use. ...

C# Need to locate web addresses using REGEX is that possible?

C# Need to locate web addresses using REGEX is that possible? Basically I need to parse a string prior to loading it into a WebBrowser myString = "this is an example string http://www.google.com , and I need to make the link clickable"; webBrow.DocumentText = myString; Basically what I want to happen is a replace of the web address ...

search and replace DOM elements in Java

I'm looking for a way to write a search and replace method using W3C DOM to update a tree. I've thought about doing a breadth-first search as below, but can't think of how to do the in place replacement? import org.w3c.dom.Node; private Element tree; public void searchReplace(Node x, Node y){ Queue<Node> q = new LinkedList<Node>(...

replace words using grep and sed in shell

I have some 150 files and in them I want to remove this following code: <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT> What I'm doing is: sed -e 's/<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/height.js"></SCRIPT>/ /' file_names This doesn't seem to work. I want to remove this script...

Find and replace in a file

i want to replace certain strings with another one in a text File( ex: \nH with ,H) .Is there any way to that using php? ...

replacing newline sed

How to replace \n from a line using sed command? ...

How to replace a Perl hash key?

Let us say if I have a hash like this: $data = { 'key1' => { 'key2' => 'value1' }, 'key3' => { 'key4' => { 'key5' => 'value2' } }, }; Now, how can I replace the the key 'key5' with some other key name say 'key6'?...

Wrapping a chunk of text with tags using PHP

I'm trying to allow a user (using Wordpress) to insert a jquery slideshow gallery (http://www.queness.com/resources/html/slideshow/jquery-slideshow.html) based on a faux tag. For example: [slideshow] <img src="url" /><br /> <img src="url" /> [!slideshow] Would produce something similar to <div id="gallery"> <a href="#"><...

Wildcards to regex in VS find & replace

I need to convert expressions of the form: return *; into: return filter(*); It seems simple enough to express it with wildcards, however, in visual studio's search & replace dailog, there's no way to associate the first asterisk with the second one. I suppose a regex can do this quite easily, however I know very little about regex...

Replace www.example.com w/ <a href="http://www.example.com">www.example.com</a>

I am not very good at regex, but I need to convert the following example from this <li>Creations by Carol - www.driedfloralcreations.com</li> to <li>Creations by Carol - <a href="http://www.driedfloralcreations.com" rel="external">www.driedfloralcreations.com</a></li> ...

Awk/Sed: How to do a recursive find/replace of a string?

How to I find and replace every occurrence of: subdomainA.example.com with subdomainB.example.com in every text file under the /home/www/ directory tree (recursive find/replace). ...

How to find and replace all occurrences of a string recursively in a directory tree?

Using just grep and sed, how do I replace all occurrences of: a.example.com with b.example.com within a text file under the /home/user/ directory tree recursively finding and replacing all occurrences in all files in sub-directories as well. ...