【问题标题】:sed to replace random numberssed 替换随机数
【发布时间】:2010-11-03 18:11:46
【问题描述】:

我需要让 sed 替换很多文件中的一些 url。每个文件都有以下内容

 http://www.expample.com/file.php?id=xxxxxxx

xxxxx 由随机数组成,每个文件中的随机深度如

file 1

_h**p://www.expample.com/file.php?id=xx

file 2

_h**p://www.expample.com/file.php?id=xxxxxxxx

等等。提前致谢。

【问题讨论】:

  • 你想用什么替换它们?
  • 你想替换什么,你希望替换文本是什么?
  • 你真的应该考虑更仔细地写你的问题。我几乎听不懂你在说什么。

标签: random sed numbers replace sh


【解决方案1】:

正如 cmets 所说,您需要告诉我们您想用什么替换它们。

但与此同时,还有一些值得细细品味的东西

sed s/id\=[0-9]+/id\=/     file*.*

如果它们是十六进制数字

sed s/id\=[0-9A-Fa-f]+/id\=/     file*.*

【讨论】:

  • 感谢您的辛勤工作,我需要将其替换为空白,例如
    sed -i 's%expample.com/file.php?id=xxxxxxx%g' file.php问题是
    随机和自动生成的数字 xxxxxxx
【解决方案2】:
sed -e "s/(http:\/\/www\.example\.com\/file\.php\?id=\d+)([^\d]|$)/YOUR_REPLACEMENT\2"

应该这样做...虽然未经测试,我现在正坐在一个没有 sed 的 Windows 盒子里。

【讨论】:

  • 嘘,坐在窗户边上!没有cygwin!
猜你喜欢
  • 2012-06-24
  • 2010-11-05
  • 2021-02-20
  • 1970-01-01
  • 2020-08-14
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
相关资源
最近更新 更多