从 php 文件中删除带有随机数(数字)的模式

从 php 文件中删除带有随机数(数字)的模式

我正在尝试使用 find 和 xargs 以及 grep 和 sed 等删除或替换大量 php 文件中的数字((随机数))。这些数字看起来像 php 文件内部的数字

 /web/20150618155933/http//www.example.com/
 src='/web/30110218335932im_/img/example.png'
( /web/20150703082231js_/https://me-ssl : /web/20150703082231/http://me-cdn')

好消息是,数字仅在 14 位数字上是静态的。但以 js_ im_ 或仅数字结尾,所以我使用以下命令

find . -type f -name '*.php*' -print0 | xargs egrep -hEo '/web/\<[[:digit:]]{14}\>/' | xargs sed -i 0 ?????

我遇到两件事 1. 与 sed 命令集成 2. 在搜索模式中添加以 js_ im_ 或仅数字结尾的内容

谢谢

答案1

以下方法对你有用吗:

find . -type f -name \*.php -exec sed -i 's:/web/[0-9]\+:/web/:g' {} \;

答案2

最终找到了这个工作

find . -type f -name '*.php*' -print0 | xargs -0 sed -i 's/\/web\/\([0-9,a-z,_]*\)[\/]//g'

多谢你们

相关内容