sed替换随机数

时间:2009-06-17 17:40:05

标签: random sed numbers replace sh

我需要让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

等。提前谢谢。

2 个答案:

答案 0 :(得分:1)

正如评论所说,你需要告诉我们你想用它们替换它们。

但同时要咀嚼的东西

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

如果它们是十六进制数字

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

答案 1 :(得分:0)

sed -e "s/(http:\/\/www\.example\.com\/file\.php\?id=\d+)([^\d]|$)/YOUR_REPLACEMENT\2"

应该这样做...虽然未经测试,我现在坐在一个无sed的Windows框中。

相关问题