The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 06:24 AM
How to replace all string instances found by find+grep umen Shell Programming and Scripting 0 12-05-2007 11:52 PM
Search for string and display those NOT found John Rihn Shell Programming and Scripting 17 05-22-2007 05:22 AM
String Search & Replace IwishIknewC UNIX for Dummies Questions & Answers 1 03-25-2006 02:28 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2006
Registered User
 

Join Date: Aug 2005
Posts: 229
Recursive Search and replace only when found string

Hello all ( again )
I will like to search and replace string in text file
ok I can loop throw the files like :
foreach f ( ` find . -name "*.[h|c]"`)
.. but here I like to examine the file if in contain the desired string
and so do the sed –e 's/blah/foo/g' thingy on it or there is better way ? ?
you see I don’t want to rename every file and rename it back
first I will like to test its content and getting true or false

hope I made my self clear
Thanks allot
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-07-2006
Registered User
 

Join Date: Aug 2001
Posts: 179
loop through all the files and use perl -p -i -e 's/blah/foo/' <filename>. This will edit the file directly and no need to copy the file and rename it
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0