The syntax you use can be also used in sed. If your sed has the -i option (perl has an option like this too), you can just edit the files directly. Else you might want to write the output of sed to a tmp file and mv it back to the original file.
If you can print the files with a find and hand them over to sed -i with -exec or xargs for example.
If you feed the filenames from a file, then a while loop may be a good idea.
Sorry not too familiar with SED commands so breaking this down so I have tried this comamnd:
sed -e '1,$s/old string/new string/g' myfirstfileinloop.txt
now when I execute this it prints to the terminal including the new strings that were replaced yet when I open the actual file it still remains the old same and nothing has changed?
As zaxxon commented, if your sed supports the "-i" option, in place change, use it.
sed -i -e '1,$s/old string/new string/g' myfirstfileinloop.txt
If it does not, you must redirect the output, like the following:
ls -1 | while read fname
do
myFileTmp=${fname}.tmp
sed -e '1,$s/old string/new string/g' "${fname}" > "${myFileTmp}"
# If you want to remove the original file uncomment the line below
[ $? -eq 0 ] && rm -f "${fname}"
done
The second option will change all files in a directory, you want one file, just:
sed -e '1,$s/old string/new string/g' myfirstfileinloop.txt > myfirstfileinloop.txt.new
Also, in the second option you can rename the tmp file to the original one:
ls -1 | while read fname
do
myFileTmp=${fname}.tmp
sed -e '1,$s/old string/new string/g' "${fname}" > "${myFileTmp}"
# If you want to change back to the original file uncomment the line below
# [ $? -eq 0 ] && mv "${myFileTmp}" "${fname}"
done