Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
So here is what I want to accomplish. I want to add the Google Analytics tracking code to all my pages on the site. They tell you to add it just before the ending body tag. So my thought was, ok, I want to do a find and replace on </body> with the code and the ending tag. Question is how do I do that from the command line. I only have ssh access to my server. I do have root access and I know where all the website files are located, so I was thinking of starting at the top of the parent directory for those files and firing off some recursive command to look for php and htm and html files with the ending body tag and replacing it with my tracking code and ending tag. I went hunting through the forums here and found a good starting command in this thread: http://www.linuxquestions.org/questi...d.php?t=346190. Below is my attempt to customize the command but I recognize a couple of problems. One, I probably need to escape forward slashes and other characters in the script. I also would like to include htm and html extensions and didn't know how to group them. Thanks for your time any any help! Darren
True. I hadn't spent too much time considering the implications. It's not a blog site, it's an ecommerce website and while there are some include pages, like a header script and a footer script, the tracking numbers for those scripts will be abnormally high but it would be easier to add the script to all our pages and then remove the ones we dont want, then to write a command to capture only the ones we do. Right? I don't have my hands around all the files that would be affected by this edit but where our product pages and category result pages are all dynamic, I think the number would be reasonable, less than 500. Is there a way to modify the command to report the files affected? That would be helpful. Darren
You could conceivably take the output of that, put it in a
file, sift through that and then let sed loose on the list
of files you actually want to modify.
for i in `cat list`
Thanks Tinkster, let me ask you this. I put the results of the find files into a file with: find /PATH -name "*php" > /PATH/findfiles.txt
Then I went through the file and trimmed it down. Now you said to
let sed loose on the list of files you actually want to modify.
for i in `cat list`
Stupid question, would this be a bash script I would be writing to run the code you provided or something else? Thanks again! Darren
It is indeed ... you can either save it with the bash-shebang line,
or just use it as a one-liner if you append a \ to each of the lines.
I split it up like this for use in a script, though.
for i in `cat list`
is the "full version" of it. Sorry about the misunderstanding.
It is, of course, untested, and I highly recommend letting it
loose on a copy of the directory structure, or some test-files
first ... :}