Global replace with sed | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Global replace with sed

Shell Programming and Scripting


Tags
solaris

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-13-2008
canary canary is offline
Registered User
 
Join Date: May 2008
Last Activity: 25 October 2008, 12:46 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Global replace with sed

Hi,

I need to change some strings from A to B in a number of files within a directory. Please can someone advise how do I do that?

Many thanks
Sponsored Links
    #2  
Old 05-13-2008
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 21 September 2014, 5:50 PM EDT
Location: H3X
Posts: 2,151
Thanks: 10
Thanked 117 Times in 110 Posts
Read this page and when you finish get back to us.
Sponsored Links
    #3  
Old 05-13-2008
canary canary is offline
Registered User
 
Join Date: May 2008
Last Activity: 25 October 2008, 12:46 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, however it will be nice if you can just put the command here. I m doing something like

find . -name "*.txt*" -type f -exec sed -e 's/ugly/bad/g' {} \;

but it doesn't like it.

Thnx
    #4  
Old 05-13-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
"It doesn't like" is not very specific, do you get an error message or surprising results or nothing at all?

You are not saving the output from sed anywhere so my guess would be you would see the files roll across your screen with the substitutions made as requested. If your sed supports the -i option then you can use that. Otherwise a simple temporary external script is probably the way to go.
Sponsored Links
    #5  
Old 05-15-2008
canary canary is offline
Registered User
 
Join Date: May 2008
Last Activity: 25 October 2008, 12:46 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I am on solaris 8 and getting illegal option error. Looks like I am using a sed which does not support sed -i

Thanks guys for your help!
Sponsored Links
    #6  
Old 05-15-2008
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 21 September 2014, 5:50 PM EDT
Location: H3X
Posts: 2,151
Thanks: 10
Thanked 117 Times in 110 Posts
Use a temp file.

Code:
 find . -name "*.txt" -type f -exec sed 's/ugly/bad/g' {} > tmp \; -exec mv tmp {} \;

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Vi global replace command DallasT UNIX for Dummies Questions & Answers 1 09-06-2011 11:48 AM
Global replace in vi with no escape required sachinpawar2308 Shell Programming and Scripting 1 11-06-2010 10:57 AM
global replace... topcat8 Shell Programming and Scripting 1 10-17-2005 01:10 AM
global replace with vi pixtond Shell Programming and Scripting 3 06-11-2004 04:54 AM
Global search ok...but replace? alan UNIX for Dummies Questions & Answers 0 03-25-2004 03:22 PM



All times are GMT -4. The time now is 12:22 PM.