sed command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

sed command

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-24-2013
macastor macastor is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 25 January 2013, 9:37 AM EST
Location: Phoenix, AZ
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
sed command

Hi all!
Need a little help on a sed command that I've used in the past, but I'd like to change it up a bit. Here is my script


Code:
SearchVal = "RED"
ReplaceVal = "BLUE"
wrkFile = /u/tmp/file1
srcFile = /usr/temp/prodfile

sed "/${SearchVal}/s/^\(.\{101\}\).\{7\}/\1${ReplaceVal}/" $wrkFile > $srcFile

What I'm looking to do is rather than using variables, I'd like to just perform the sed command without variables. Such as....

Code:
sed "/${RED}/s/^\(.\{101\}\).\{7\}/\1${BLUE}/" /u/tmp/file1 > /usr/temp/prodfile

I've tried without the "$'s" but that didn't work? am I missing something??

Thanks!
Sponsored Links
    #2  
Old 01-24-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 July 2014, 1:11 AM EDT
Location: Amsterdam
Posts: 9,281
Thanks: 260
Thanked 2,303 Times in 2,066 Posts
Yes you would need to leave out the curly brackets too, that belong to the shell variables. Try:

Code:
sed "/RED/s/^\(.\{101\}\).\{7\}/\1BLUE/"

The Following User Says Thank You to Scrutinizer For This Useful Post:
macastor (01-25-2013)
Sponsored Links
    #3  
Old 01-25-2013
macastor macastor is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 25 January 2013, 9:37 AM EST
Location: Phoenix, AZ
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
Ahhh! Thanks Scrutinizer!
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
sed returns error "sed: -e expression #1, char 18: unterminated `s' command" anand.shah Shell Programming and Scripting 8 10-15-2012 09:53 AM
sed insert command and variable expansion/command substitution glev2005 UNIX for Dummies Questions & Answers 8 03-09-2010 02:18 PM
Convert Sed command to perl command abacus Shell Programming and Scripting 2 11-10-2009 11:25 AM
Loop with sed command to replace line with sed command in it cbo0485 Shell Programming and Scripting 1 08-27-2009 11:19 AM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 12:29 PM



All times are GMT -4. The time now is 05:04 AM.