我一直在使用簡單的find命令來搜索數百個html文件,然後替換每個文件中的一些簡單文本。只打開包含特定字符串的文件,然後在Linux命令行上替換
查找並列出包含搜索字符串的文件。
find . -iname '*php' | xargs grep 'search-string' -sl
,給了我的文件的簡單列表喜歡。
./javascript_open_new_window_form.php
./excel_large_number_error.php
./linux_vi_string_substitution.php
./email_reformat.php
./online_email_reformat.php
搜索和替換我使用的字符串。
sed -i 's/search-string/replace-string/' ./javascript_open_new_window_form.php sed -i 's/search-string/replace-string/' ./excel_large_number_error.php sed -i 's/search-string/replace-string/' ./linux_vi_string_substitution.php sed -i 's/search-string/replace-string/' ./email_reformat.php sed -i 's/search-string/replace-string/' ./online_email_reformat.php
所以我的問題是...我怎麼能結合兩個命令,所以我不必須手動複製和每次粘貼文件名。
感謝您的幫助提前。再次
find . -iname '*php' | xargs grep 'search-string' -sl | while read x; do echo $x; sed -i 's/search-string/replace-string/' $x; done