Complex Search/Replace Multiple Files Script Needed

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex Search/Replace Multiple Files Script Needed
# 1  
Old 07-21-2009
Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like

die("Operation Aborted due to.....");

For my new design skins for the site, I need to get rid of these statements and transform them into something like

echo "Operation Aborted due to.....";$h->endpage();exit;

So it really takes the first part: die(" and replaces it with Echo "
And then, on the same line only, replace: ); with ;$h->endpage();exit;

Is there anyway this can be done or am I really going to have to manually go through all pages to make these changes? Thanks.


---------- Post updated at 07:23 PM ---------- Previous update was at 07:11 PM ----------

So I figured out an solution...

I am simply going to do a search/replace on the Die function and rename the function to something new. I can then write my own function to do what I originally needed.

Now I find myself unable to discover where on this forum I can delete my post to save everyone time. Smilie Well thanks for reading.

Last edited by UCCCC; 07-22-2009 at 02:35 PM..
# 2  
Old 07-22-2009
If you have found out the solution to problem, I hope you don't mind to post the solution as well, as that might help other users in the forum
# 3  
Old 07-22-2009
I assume you are asking me to provide a more clear explanation of what I did. Okay.

From the linux command prompt, I ran the following commands, which perform a search and replace for die(" and also die (" and replace the die function with a new function name called diefunc for all my files of extension .php

perl -pi -w -e 's/die\("/diefunc\("/g;' *.php
perl -pi -w -e 's/die \("/diefunc \("/g;' *.php

Tutorial found here:
Linux - Search and replace over multiple files.

I then created a new function diefunc

function diefunc($text)
        global $h;
        echo $text;$h->endpage();exit;

My site has a global function .php file which is included in all my site pages, and it is there where I created this global function to be used on all the PHP pages now using the diefunc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

Search and Replace in multiple files

Hello, I have hundreds of files in which I need to change email address. Here is what I am trying to do: 1. All text files are in a directory "a" 2. In the text file, I want to replace email address for preparer. All these lines start with {{PreparerEmail and end with }}. The email... (3 Replies)
Discussion started by: cartrider
3 Replies

4. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

5. Shell Programming and Scripting

perl: search replace in multiple files

When I use special characters the command to replace multiple files with a string pattern does nt work. ---------- Post updated at 12:33 PM ---------- Previous update was at 11:38 AM ---------- This works perl -pi -e 's/100/test/g' * This does nt work perl -pi -e 's... (1 Reply)
Discussion started by: w020637
1 Replies

6. Shell Programming and Scripting

String search and replace in multiple files.

Hello. I have five config files in /etc that I want to edit in one click for testing. I would like to make a script like this : #!/bin/bash # a_file="/etc/file_1" src_str="src_string_1" rpl_str="rpl_string_1" calling_sed_or_awk_or_whatelse $a_file search_for_all $src_str replace_with... (4 Replies)
Discussion started by: jcdole
4 Replies

7. Shell Programming and Scripting

Global search and replace across multiple files

Hi all I'm in need of a command which can replace a specified string with another string - across multiple files within multiple sub-directories (I intend to run it from / ) I've used the following to get a list of the files: find . | xargs grep <string1> But that's as far as I've got.... (7 Replies)
Discussion started by: huskie69
7 Replies

8. Shell Programming and Scripting

Need to search and replace in multiple files in directory hierarchy

Hello all I need to search and replace in multiple files that are in directory hierarchy Im using the : find . -name "*.dsp" -print | xargs grep -n -o Test.lib" , I like to be able to replace every instance of Test.lib with empty space . how can I write one liner that does this ? (3 Replies)
Discussion started by: umen
3 Replies

9. UNIX for Dummies Questions & Answers

multiple input search and replace script

hi, i want to create a script that will search and replace the values inside a particular file. i have 5 files that i need to change some values inside and i don't want to use vi to edit these files. All the inputted values on the script below will be passed into the files. cho "" echo... (3 Replies)
Discussion started by: tungaw2004
3 Replies
Login or Register to Ask a Question