Solved

Changing code in multiple files that span several directories

Posted on 2006-07-05
2
225 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now