need help on sed (replace string without changing filename)

I have awhole bunch of files and I want to edit stringA with stringB without changing the filename.

I have tried the following sed commands:

sed "s/stringA/stringB/g" *

This will print the correct results but does not actually save it with the new content of the file. when I do a cat on the filename it still shows stringA.

THANKS

That's because sed (by default) doesn't change the contents of the file in place.

Do something like

for file in *
do
  sed 's/stringA/stringB/g' $file > $file.new
  mv $file.new $file
done

Cheers
ZB

Im not familiar with script writing - but I tried to create a file with the following code you had then ran

sed -f script

and nothing happen.

how would I execute those script?

THANKS -- I dont normally do this type of work but your help is much appreciated.

Create a script, let's say "foo.sh" with the following code

#!/bin/sh

for file in /path/to/my/files/*
do
  sed 's/stringA/stringB/g' $file > $file.new
  mv $file.new $file
done

exit 0

Make the script executable
$ chmod u+x foo.sh

Then run it (assuming it's in the current directory)
$ ./foo.sh

Cheers
ZB

THANK YOU VERY MUCH ZB -- now I know how to write a script....

I personaly prefer perl for string replacement instead of sed

#/bin/bash
printf "Enter the String to be replaced: "
read ostring
printf "Enter the String to be substituted: "
read rstring
printf "Enter the Path of the files: "
read path
cd $path
files = `ls`
for file in $files
do
perl -p -i -e 's/$ostring/$rstring/' $file
done

Chill
enc;-)