我仍在使用这个小脚本,但仍然遇到问题。得到错误
sed: no input files
我认为问题出在:
for i in `cat sed_output.txt` do sed 's/$oldstr/$newstr/g' > sed_output_new_old_string.txt done
echo "Enter string to be replaced"
read OLDSTRING
echo "Enter string to be placed"
read NEWSTRING
oldstr=$OLDSTRING #string to be replaced
newstr=$NEWSTRING #new string to be placed
echo "Enter folder path where we will find the string"
read FOLDERPATH
### grep oldstring and output it in grep_output.txt
grep -rl $oldstr $FOLDERPATH > grep_output.txt
### spaces or special characters on filenames, use sed to enclose them with quote
for i in `cat grep_output.txt`
do sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" grep_output.txt > sed_output.txt
done
for i in `cat sed_output.txt`
do sed 's/$oldstr/$newstr/g' > sed_output_new_old_string.txt
done