Sponsored Content
Top Forums Shell Programming and Scripting Search & Replace: Multiple Strings / Multiple Files Post 302716683 by spacegoose on Tuesday 16th of October 2012 06:26:24 PM
Old 10-16-2012
Data Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g.

Code:
/home/1/foo/bar.x
/www/sites/moose/foo.txt

I'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 are around 120 substitutions and around 4,600 files.

One issue: these strings are passwords, I'm hoping not to need to escape them.

So far I've only come up with:

Code:
ggrep -HF -f /home/pass "/home/find-passwords/struc/www/sites/foo.php"

which doesn't do much except list the file and matched string from pass (which contains old passwords),

no escaping is required due to the -F arg to grep.

e.g.

Code:
ggrep -HF -f /home/pass "/home/find-passwords/struc/www/sites/foo.php"

returns:

Code:
/home/find-passwords/struc/www/sites/foo.php:$dbcnx = @mysql_pconnect("blah.com", "foo", "xfgt^5");

where xfgt^5 is the match from my /home/pass file.

I'm struggling with how to replace the old password with the new, and thinking loops with a bunch of ifs might work? Or a lookup table?

I can put the old and new passwords in a file with corresponding columns.

It would be nice to be able to run in a manner that shows what it will do, and then one that does it.

Thanks for any help,

Bill

Last edited by spacegoose; 10-17-2012 at 09:52 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

2. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

3. 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

4. UNIX for Dummies Questions & Answers

how to find and replace strings in multiple files

Hi All, Iam new to unix, I need to find string and replace it in the file name. Like text_123_0.txt,text_123_1.txt,text_123_2.txt. I need to search 123 and replace it with 234 . Is there any unix command to replace them in single command since i have 5 directories. So i need to go each and every... (0 Replies)
Discussion started by: etldeveloper
0 Replies

5. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

6. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

7. 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

8. 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

9. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains: Input file: value1 = url1 value2 = url2 value3 = url3 and so on. I need to search all *.xml files under directory for value1 and replace it with url1. Same thing I have to do for all values mentioned in input file. I need script in unix bash... (7 Replies)
Discussion started by: Shamkamde
7 Replies

10. 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
CLASSKIT_IMPORT(3)							 1							CLASSKIT_IMPORT(3)

classkit_import - Import new class method definitions from a file

SYNOPSIS
array classkit_import (string $filename) DESCRIPTION
Note This function cannot be used to manipulate the currently running (or chained) method. Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. PARAMETERS
o $filename - The filename of the class method definitions to import RETURN VALUES
Associative array of imported methods EXAMPLES
Example #1 classkit_import(3) example <?php // file: newclass.php class Example { function foo() { return "bar! "; } } ?> <?php // requires newclass.php (see above) class Example { function foo() { return "foo! "; } } $e = new Example(); // output original echo $e->foo(); // import replacement method classkit_import('newclass.php'); // output imported echo $e->foo(); ?> The above example will output: foo! bar! SEE ALSO
classkit_method_add(3), classkit_method_copy(3). PHP Documentation Group CLASSKIT_IMPORT(3)
All times are GMT -4. The time now is 10:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy