Find all .sh files in file system and need to replace the string inside .sh files

Hi All,
I need to write a script to find all ".sh" files in /home file system and if any string find ".sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this.

find / -name "*.sh" -print 2>/dev/null

Try

awk '{gsub ("vijay@gmail.com", "vijay.bhaskar@gmail.com")} 1' $(find /home -name "*.sh")
1 Like

Running find against / (root) is not great idea.

Run your code as a non-privleged user.

Try

find /  -type f -name '*.sh' -exec grep -l 'vijay@gmail.com'  {} \; > ~/mylist

then check the list. If you like it:

while read filename 
do
    sed  -i 's/vijay@/vijay.bhaskar@/g' $filename
done  <  ~/mylist

If you hit permission errors then you need to rethink what you are doing because you may have selected system files you should not have changed earlier.
You can run the file loop statement over and over until you are error free. Why? Because will not change anything in files it already fixed.

Check back here if you need help.
Edit:
Rudi beat me to an answer. I still think a little caution is good idea as well.

1 Like

Hi Jim,

Thanks so much for your suggestions. I am very happy with your solution.