View Full Version : Linux Command Question

02-13-2002, 06:50 PM
I want to replace every occurance of with in every file in a specific folder.

What linux command could i use to do this?



02-22-2002, 06:33 PM
Oh it's like on the tip of my tougue but I can't remember the actual command.

What I use is homesite from http://www.allaire.com You can open several web pages at a time and replace the text or portion of text in every page in one or two clicks.

If I can remember the vi command I'll definately let you know.

02-22-2002, 06:42 PM

Phew braincell is smoking now:

Here goes

Open the file to edit in vi

To replace Do this ...
pattern1 with pattern2 :s/pattern1/pattern2 on the same line

every occurrence of pattern1 :g/pattern1/s//pattern2/g with pattern2

You may run into trouble with the characters in the text you're trying to change I'm not sure. I would make a copy of a file first and practice on that.

I'll see if I can dredge up a better way to so rather than file by file as well.


02-22-2002, 06:52 PM
Last post I promise,

You can open several files in vi at once but you'll still have to switch from one to the other to make your replacement. For example:

You open test.html and test1.html by typeing in
vi test.html test1.html

You now have both files open and are viewing test.html

Once you've replaced your text as noted in above post type :wq to save your changes and then :n to switch to the next one and so on. Kinda a pain but it works.

I still think the easiest solution is Homesite but what ever works best for you is what's important. Just tryin to help out.


02-22-2002, 06:55 PM
Alright I lied,

The text you want to replace vi wont work, because of the characters involved, so hey, go check out and download the eval of Homesite I think you'll find it's a cinch to learn, it's like a glorified notepad editor with super extra's SPAM;D

At we all learned a few new tricks in vi huh?

Gone for real this time SPAM:-X

02-22-2002, 07:49 PM
I figured out a way to do it.

I searched on google and found a small, one line, perl script that will open every file, search + replace, and then make a back up of the file. SPAMI do not have the syntax right here but when I find it I will definetly post it for all to see.


02-23-2002, 12:59 PM
Oh sure,

After I scrap my braincell you leave a tease SPAM:o in place SPAM:D

I'd like to use the script myself, so when you find it please do post it.