Replace String in Multiple Files using Unix Command

Shell Script allows you to replace string in multiple files using unix / linux command.

Features

  • Can replace string in multiple files using unix / linux command.
  • This shell script works in Linux operating system only.
  • It reduces time to replace string in multiple files
  • Easily customizable and configurable.

Downloads



#------------------Script by hscripts.com------------------#
#--------------More scripts @www.hscripts.com---------------#
OLDSTRING="string to be replaced"
NEWSTRING="String to be replaced with"
FOLDERPATH="/opt/lampp/htdocs/test/shell/*.php"
NEWFOLDERPATH="/opt/lampp/htdocs/test/shell-test/"
[ ! -d $NEWFOLDERPATH ] && mkdir -p $NEWFOLDERPATH || :
for f in $FOLDERPATH
doecho $ffname=`basename $f`
sed "s#$OLDSTRING#$NEWSTRING#g" "$f" > "$NEWFOLDERPATH""$fname"
echo $fname
done
# OLDSTRING
- String to be replaced #
# NEWSTRING
- String to be replaced with OLDSTRING #
# FOLDERPATH
- Folder path with files #
# NEWFOLDERPATH- Result folder with replaced strings in all files #
#---------------- Script by hscripts.com-------------------------#




  • Release Date - 14-05-2014
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to support@hscripts.com

Usage

  • Copy the above code and save it with .sh extension
  • Assign the foldername for variable FOLDERNAME in the code under which you want to replace the strings in all files .
  • Execute the above linux shell script as sh filename.sh to remove the particular string in multiple files of same folder recursively.
  • Finally it gives you the newfolder with replaced string in all files.

License

Other Scripts


Ask Questions

Ask Question