Fedora Linux Support Community & Resources Center
  #1  
Old 23rd October 2010, 09:23 PM
Vector's Avatar
Vector Offline
Banned
 
Join Date: Jul 2006
Location: Transgression
Age: 33
Posts: 1,183
linuxfedorafirefox
[SOLVED] Using find with sed to replace variables in php files?

Ok, so i've got this command that i'm playing with, which is a modification of an mp3gain command example that i seen; but my modification is not working, so i was wondering if i can even DO this in this way:
Code:
find '/home/1_Logic' -name *.php -exec sed 's/\$title/\$system['title']/g' {} \;
It does traverse through all of the files, but it doesn't replace anything. I tried with and without the backslashes. It made no difference.

Also tried this, with and without backslashes, to no avail:
Code:
find '/home/1_Logic' -name '*.php' | xargs perl -pi -e 's/$title/$system['title']/g'
I've also tried escaping the single quotes around the php array index, and even removing them altogether just to see if it works, to no avail...

I've also tried this, which seemed promising, but didn't work:
Code:
find '/home/1_Logic' -name '*.php' | xargs perl -w -p -i -e 's/\$title/\$system[''title'']/g'
Thanks

===EDIT===

Got it working!:
Code:
find '/home/1_Logic' -name '*.php' | xargs perl -w -p -i -e 's/\$title/\$system['"'"'title'"'"']/g'
Now i can update my ENTIRE frame work in 1 night, as opposed to 3 months . A search and replace that would have taken me HOURS for each variable (i've got over 3,000 files in my framework) now takes less than 1 second!

===EDIT===

But i still can't figure out how to do something like this:
Code:
find '/home/0_Logic' -name '*.php' | xargs perl -w -p -i -e 's/\$system['"'"'http'"'"']/\$system['"'"'protocol'"'"']/g'
===EDIT===

Got it:
Code:
find '/home/0_Logic' -name '*.php' | xargs perl -w -p -i -e 's/\$system\['"'"'time'"'"'\]stamp/\$system['"'"'timestamp'"'"']/g'

Last edited by Vector; 24th October 2010 at 01:31 AM.
Reply With Quote
  #2  
Old 24th October 2010, 04:46 PM
assen Offline
Registered User
 
Join Date: Oct 2008
Posts: 492
linuxfedorafirefox
Re: Using find with sed to replace variables in php files?

Hi,

Google for a tool named "rpl". It does hell of a good job in recursively replacing strings in files.

WWell,
Reply With Quote
  #3  
Old 5th November 2010, 03:25 AM
Vector's Avatar
Vector Offline
Banned
 
Join Date: Jul 2006
Location: Transgression
Age: 33
Posts: 1,183
linuxfedorafirefox
Thumbs up Re: Using find with sed to replace variables in php files?

Code:
# yum -y install rpl
# man rpl
Haven't had to use it yet, but it looks great. Thanks!
Reply With Quote
Reply

Tags
files, php, replace, sed, variables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
after a crash, which files went bad and how to replace? Nick Levinson Using Fedora 1 7th March 2009 07:23 PM
I want to find and replace across multiple lines and do it recursively. reashlin Linux Chat 14 9th October 2008 02:42 PM
phpmyadmin how do you find > and replace? 105547111 Using Fedora 2 28th June 2007 02:07 PM
Environment variables in SPEC files daihard Using Fedora 14 8th April 2006 03:09 AM


Current GMT-time: 23:34 (Wednesday, 19-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat