Thursday, April 28, 2011

sed to replace random numbers

Hello,

i need to let sed replace some url in alot of file each file has the following
http://www.expample.com/file.php?id=xxxxxxx
where xxxxx consist of random numbers , random depth in each file like
file 1
_h**p://www.expample.com/file.php?id=xx
file 2
_h**p://www.expample.com/file.php?id=xxxxxxxx
etc
thanks in advance

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

    should do it... Untested though, I'm sitting at a sed-less Windows box right now.

    Malfist : boo for sitting at a windows box! And no cygwin!
  • As the comments say you will need to tell us what you want to replace them with.

    But in the mean time something to chew on

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

    if they are hex digits

    sed s/id\=[0-9A-Fa-f]+/id\=/     file*.*
    
    AYAK : thanks for your hard work, i need to replace it with blank like
    sed -i 's%expample.com/file.php?id=xxxxxxx%g' file.php the problem is
    the random and auto generated numbers xxxxxxx

0 comments:

Post a Comment