Computing.Net > Forums > Unix > trouble with c-shell script & sed

trouble with c-shell script & sed

Reply to Message Icon

Original Message
Name: dead man
Date: November 19, 2002 at 17:23:34 Pacific
Subject: trouble with c-shell script & sed
OS: win 98
CPU/Ram: intel 4/ 512 MB DDRSDRAM
Comment:

Can someone help with the script i'm trying to write; it uses sed. I think i'm doing something wrong with syntax. The script is supposed to replace str1 with str2 in any number of files....... I'm having trouble with sed recongnizing the 2 string arguments

version of unix is SunOS 5.8
HERE IS CODE::::::

UW PICO(tm) 4.0 File: replace Modified

#!/bin/csh

set find = $1
set replace = $2
@ count = 0
@ x = $#argv - 2

while($count < $x)


sed 's/$find/$replace/g' $3
shift
@ count++
end

***************
ANY help is greatly appreciated
thanks



Report Offensive Message For Removal


Response Number 1
Name: n
Date: November 19, 2002 at 19:53:22 Pacific
Subject: trouble with c-shell script & sed
Reply: (edit)

Hi,

Adding brackets may help.

sed 's/${find}/${replace}/g' $3


Report Offensive Follow Up For Removal

Response Number 2
Name: Jimbo
Date: November 19, 2002 at 23:50:08 Pacific
Subject: trouble with c-shell script & sed
Reply: (edit)

sed won't perform variable substitution using single quotes. try this:

sed "s/$find/$replace/g" $3

-jim


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: trouble with c-shell script & sed

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge