I am trying to remove or replace the digits ((random numbers)) in big numbers of php files using find & xargs and grep with sed etc .. the numbers looks like that inside the php file

( /web/20150703082231js_/https://me-ssl : /web/20150703082231/http://me-cdn')

the good things the numbers is static on 14 digits only .. but end with either js_ im_ or only numbers,, so i was use the below command

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

i stuck in two things 1. integrated with sed command 2. add in search Pattern end with either js_ im_ or only digits numbers


2 Answers 2


Would something like this work for you:

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


  • nop , I've run it doesn't do anything Nov 5, 2015 at 22:34
  • It does work as expected. Please do not downvote without before attempting troubleshooting. Your system details might help helping you.
    – SΛLVΘ
    Nov 5, 2015 at 23:37

in the end found this work with me

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

thanks guys

  • (1) Yes, \/ works, but, when you are doing a search and replace that includes slashes, it’s often clearer to use some other character as the delimiter.  I like vertical bar (|); other people prefer !, @, #, or anything else that doesn’t otherwise appear in the command and isn’t a special character.  (2) […] counts as a single regular expression; therefore, so does […]*.  So you don’t need to enclose it in \(…\) (unless you’re inserting it as part of the replacement string).  (3) Don’t include , in a […] expression unless you want it to match a comma.  … (Cont’d) Nov 7, 2015 at 21:20
  • (Cont’d) …  (4) I know your examples don’t show any capital letters, but, do you have capital letters in your data?  If you do, you need to include A-Z in your regex.  (5) Why did you put the last \/ into brackets?   Just for clarity?  (6) Your sed command can be compressed to 's|/web/[0-9a-z_]*/||g' (or, if applicable, …[0-9A-Za-z_]*…). Nov 7, 2015 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.