Help - Search - Members - Calendar
Full Version: Calling for shell programmers to write a simple script...
The Planet Forums > Operating Systems > Red Hat Linux
mahiraminc
Hi there...

My situation: I have hundreds of .ram files in directories and sub directories.

In the ram files I basically have a link such as...

http://www.ev1.net/music/song1.rm

Now... I just changed the domain from ev1.net to ev2.net. It will truly be a pain to download all these ram files and edit them manually. I tried downloading in batches and using EditPlus editing them in bluk but even EditPlsu crashes because there are just so many!

Is there a shell command I can use to some how read the contents of all the files under a directory (and its subdirectories) and replace a string?

I am sure there is but just now knowledgeable enough to write it myself.

Can anybody put together some simple code for me? Thanks and I really appreciate it.

I'm a web design/developer.... let me know if you need any help. Thanks!
linux_phantom
I have a way, using perl

go to each subdirectory and run

perl -i -pe 's/ev1.net/ev2.net/g' *.ram


this will do it for you.
mahiraminc
Can this code be modified to run recursively...

I mean, I would like to run it on the main directory and haev all the sub directories be searching for ev1.net and replace it by ev2.net. The file type to be searched for is .ram

Going into each directory will be a big pain... thanks.
linux_phantom
Ummmmmm, just run this

for i in `find . -name "*.ram"`; do perl -i -pe 's/ev1.net/ev2.net/g' $i; done
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.