Linux更改文件特定字符串,只打开包含特定字符串的文件,然后在Linux命令行上替换...

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值