Solved

Changing code in multiple files that span several directories

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
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 …

914 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

15 Experts available now in Live!

Get 1:1 Help Now