Solved

Changing code in multiple files that span several directories

Posted on 2006-07-05
2
228 Views
Last Modified: 2010-04-22
Hello All,

I have an APACHE web server running on Linux and I have to update some PHP code across several directories within the home directory.

All the files have the same name and are found in each subdirectory off of the home directory. Here are the names:

1. eventcalendar.php
2. eventcalendaradd.php
3. eventcalendaredit.php

All I need to do is replace the word "OTHER" in the below referenced code with "SC":

<?php if (empty($x_EventCode)) { $x_EventCode = "OTHER"; } // set default value ?><?php
$x_EventCodeList = "<select name=\"x_EventCode\"><option value=\"\">Please Select</option>";
$x_EventCodeList .= "<option value=\"" . htmlspecialchars("OTHER") . "\"";
if (@$x_EventCode == "OTHER") {
      $x_EventCodeList .= " selected";
}

I am pretty sure this can be done with SED or AWK, but I am not quite sure how. If anyone knows of a solution, I would appreciated it greatly.

Sincerely,

Bruce
0
Comment
Question by:safepointmedia
2 Comments
 
LVL 24

Accepted Solution

by:
slyong earned 500 total points
ID: 17046230
You can use a command like:

find ./ -type f -exec sed -i 's/OTHER/SC/' {} \;

but be a bit careful.. all OTHER will be replaced by SC.. this includes ANOTHER will become ANSC...
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17046492
You can make slyong's script more robust:

find ./ -type f -exec sed -i 's/"OTHER"/"SC"/' {} \;
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
partition customisation for kickstart file 2 94
Stopping flocksnippet: Killed (core dumped) on doing kill -9 5 73
how does yum update work 2 55
Help with Ubuntu 14.04 LTS 10 135
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question