how to find and replace strings in multiple files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to find and replace strings in multiple files
# 1  
Old 02-11-2011
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 directory.
I need to replace 123 with 234 in each directory. Please give any suggestions

Last edited by etldeveloper; 02-11-2011 at 01:55 PM.. Reason: Moved from AIX forum
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and replace from multiple files

Hello everybody, I need your help. I have a php site that was expoited, the hacker has injected into many php files a phishing code that was discovered and removed in order to have again a clean code. Now we need to remove from many php files that malware. I need to create a script that find and... (2 Replies)
Discussion started by: ninocap
2 Replies

2. Shell Programming and Scripting

Find and replace in multiple files

Hi, I have php files in main dir and sub dir's as well. I need to find "new mysqli('localhost', 'System', 'xxxxxx', 'System', '3306');" and replace as "new mysqli('localhost', 'unx_sys', 'yyyy', 'unx_sys', '3306');" I tried like: sed 's/new mysqli\(*\)\;$/new... (1 Reply)
Discussion started by: ashokvpp
1 Replies

3. Shell Programming and Scripting

Find multiple strings and replace single string

Hi, following Perl code i used for finding multiple strings and replace with single string. code: #!/usr/bin/perl my @files = <*.txt>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr = ',rdata\)' | ',,rdata\)' | ', ,rdata\)'; my $replaceStr =... (2 Replies)
Discussion started by: chettyravi
2 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

How to find multiple strings within files under a directory

Hi guys, I need to find multiple strings within files under a directory and secondly, to count how many files are there with these strings. At present, i am able to do this in order to find one string (for example "abc"): find <path> -exec grep "abc" {} /dev/null \; Now for example, i... (2 Replies)
Discussion started by: frum
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. UNIX for Dummies Questions & Answers

Find Multiple Strings from a list of *.gz files withour decompressing...

Hello Team, There is this situation where there are around 20 *.gz files and i want to search multiple words from all those files. Example as below : filea.gz fileb.gz filec.gz now i want to search words "hi" and "hello" from all these 3 files without... (4 Replies)
Discussion started by: varun87
4 Replies

8. Shell Programming and Scripting

awk find and replace in multiple files

Hi I use the following code to replace ‘.' with ‘N' in my files and keep both versions. awk '{ gsub(/\./,"N"); print }' file_0001.txt > path/to/new/dir/file_0001.txt I need help on how to apply the code to 100 files instead of doing them one file at a time. The files are labeled... (7 Replies)
Discussion started by: jdhahbi
7 Replies

9. Shell Programming and Scripting

Help with Find/Replace Javascript Injected Strings in mulitple files

Hi, guys, I'm not a high-end programmer, but I've been trying to write a script to remove all of the b.rtbn2.cn (and b.adserv.cn and any future variation) injected script tags on the server. (Still working on security fixes to prevent it in the future, just need to clean up now.) My approach is... (1 Reply)
Discussion started by: zzlegs
1 Replies

10. Shell Programming and Scripting

Find and replace files in multiple folders

Hi there, I would like to write a script to automate the copy and renaming of files in multiple dir. I have a generic file named s253e.prb and would like to copy this to multiple dir and rename it. Example: Dir is AL-M1 and the prb file name is AL-M1.prb. I would like to be able to... (6 Replies)
Discussion started by: lodey
6 Replies
Login or Register to Ask a Question
RPL(1)							    BSD General Commands Manual 						    RPL(1)

NAME
rpl -- replace strings in files SYNOPSIS
rpl [-LhiwbqvsRepfdt] [-xSUFFIX] <old_string> <new_string> <target_file ...> DESCRIPTION
Basic usage is to specify two strings and one or more filenames or directories on the command line. The first string is the string to replace, and the second string is the replacement string. -h, --help A short help text. -L, --license Show the license and exit. -xSUFFIX Search only files ending with SUFFIX, e.g. ``.txt''. May be specified multiple times. -i, --ignore-case Ignore the case of old_string. -w, --whole-words Make old_string match only on word boundaries. -b, --backup Move the original files to filename~ before replacing them. -q, --quiet Quiet mode. -v, --verbose Verbose mode. -s, --dry-run Simulation mode, no files are changed. -R, --recursive Recurse into subdirectories. -e, --escape Expand escape sequences in old_string and new_string. Examples of escape sequences are ' ' (new-line), ' ' (tab), 'x42' (hexadec- imal number 42), '33' (octal number 033). -p, --prompt Prompt for confirmation before replacing each file. -f, --force Ignore errors when trying to restore permissions and file ownership. -d, --keep-times Keep modification times when replacing files. -t, --use-tmpdir Use a temporary directory for storing temporary files, usually the value of the environment variable TMPDIR. The default is to put temporary files in the same directory as the file being modified. -a, --all Do not ignore files and directories starting with . IMPLEMENTATION NOTES
An effort has been made to make the program behave as much as the original rpl as necessary. Where it has been possible to make improve- ments, improvements have been made. This implementation lacks many of the bugs in the original. EXAMPLES
Replace all occurences of ``F'' (on word boundaries) with ``A'' in all text files under the grades/ directory: $ rpl -Rwd -x'.txt' 'F' 'A' grades/ SEE ALSO
find(1), sed(1). HISTORY
This program was written for Debian as a free replacement for the non-free rpl program by Joe Laffey. AUTHORS
Goran Weinholt <weinholt@debian.org>. Debian July 31, 2005 Debian