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
find and replace javeed7 Shell Programming and Scripting 1 04-02-2008 06:00 AM
find and replace mahabunta UNIX for Dummies Questions & Answers 7 09-21-2006 09:05 AM
find and replace valhutch UNIX for Dummies Questions & Answers 4 07-29-2006 02:20 PM
find and replace vikas_j@hotmail UNIX for Dummies Questions & Answers 3 02-25-2002 02:41 PM
Find & Replace gagansharma Shell Programming and Scripting 3 11-27-2001 01:17 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-23-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
find and replace

Hi,

There are some "n" files in a directory which contains comman string.A command to find and replace the string in all the files without looping.

like if i am in a directory :

# find ./ -name ".txt" | xargs sed -e 's/test/tst'
Upto here is performed correctly and i want to redirect this to the same files.( ie ".txt" replcace )

( As sed replaces but does modify the files so need to redirect to the same files )

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-23-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Quote:
Originally Posted by rakshit View Post
# find ./ -name ".txt" | xargs sed -e 's/test/tst'
Upto here is performed correctly and i want to redirect this to the same files.( ie ".txt" replcace )

If you have GNU sed

Code:
find ./ -name ".txt"  | xargs sed -i -e 's/test/tst/g'
Or with perl

Code:
find ./ -name ".txt"  | xargs perl -pi -e 's/test/tst/g'
Reply With Quote
  #3  
Old 01-23-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
GNU sed has the -i option (inline edit) which you are looking for

otherwise, use perl instead of sed:
Code:
perl -pi -e 's/test/tst/'
Reply With Quote
  #4  
Old 01-23-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
re

I am on HP Unix.

sed has no option "-i" for sed.

perl -pi -e 's/test/test'

Substitution replacement not terminated at -e line 1.
Can't open perl script "s/e/t": No such file or directory

I want to redirect to the same files in the directory
Reply With Quote
  #5  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
needs the / delimiter on the end of the regexp:

perl -pi -e 's/test/test/'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
gnu sed, perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:50 AM.


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

Content Relevant URLs by vBSEO 3.2.0