Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have thousands of web files(*.php, *.htm, *.html, etc) that contain an absolute path(http://site.com/sites/etc). I need to scan a directory and all subdirectories for the various file types and within those files, modify my absolute path to a relative one of my choosing and then leave the rest of the file as is. It must not change the path of any other absolute URLs though.

I've checked the similar questions already posted on the matter but none seem to address this directly. Any suggestions? Thanks!

share|improve this question

1 Answer 1

up vote 4 down vote accepted
find . -type f -print | 
  xargs sed -i.bak 's#http://site.com/sites/etc#something else#g'
share|improve this answer
    
I think that will do it. There is a test flag for sed, right? –  Publiccert Feb 27 '12 at 18:00
    
Since -i.bak will create the backups in their current web accessible location, could I suggest that you move them after the operation is complete? You probably want to avoid an potential for exposing your server side bits as plain text. –  Aaron Copley Feb 27 '12 at 18:32
    
@AaronCopley That's a good point. Luckily, this is just the data migration. None of the externally routable IPs are pointing to this site yet. –  Publiccert Feb 27 '12 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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