我一直在使用简单的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