0
我仍然在使用這個小腳本,但仍然有問題。收到錯誤遞歸變化sed grep和sed
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
我在'貓grep_output.txt' 做的sed -i 「S/$ oldstr/$中newstr/G」 $ I> sed_output_new_old_string.txt 做 – jmazaredo
你不需要做'cat'做的,因爲我。默認情況下'sed'會一行一行地解析文件。你可以簡單地執行'sed's/$ oldstr/$ newstr/g「grep_output.txt>新文件'。如果您將輸出重定向到新文件,則不需要'-i'選項。它僅適用於文件更改。 –