Unix Shell - string problem using sed

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > string problem using sed





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author string problem using sed
mike

2006-11-29, 1:17 pm

Hi,

I am using sed in a shell script ( se below). I get a problem with the
replace string ( $2).
the '-I' is intepreted as an option to sed. How can I avoid that?

cheers,

//mikael

search_replace (){
echo "Search for $1 to replace with $2"
sed 's/$1/$2/' "$3" >"$3.tmp"
}

type_sigbase="/vobs/rbs/sw/blibss_1/blibss/blibcedtsyslu/external_src/
-I /vobs/rbs/sw/blibss_1/blibss/blibsigbasendlu/src/"

find . -type f -maxdepth 1 -name '*sig.sh' |
while read file
do
echo "Processing $file ...."
search_replace /vobs/rbs/sw/rbssw_architect/rbsmdlu/
${type_sigbase} $file
cat "$file.tmp" >"$file"
rm -f -- "$file.tmp"
done

Bill Marcum

2006-11-29, 1:17 pm

On 29 Nov 2006 09:33:45 -0800, mike
<mikaelpetterson@hotmail.com> wrote:
> Hi,
>
> I am using sed in a shell script ( se below). I get a problem with the
> replace string ( $2).
> the '-I' is intepreted as an option to sed. How can I avoid that?
>
> cheers,
>
> //mikael
>
> search_replace (){
> echo "Search for $1 to replace with $2"
> sed 's/$1/$2/' "$3" >"$3.tmp"
> }

Parameters and variables are not expanded in single quotes.
Also, since $1 and $2 are likely to contain slashes, use another character
as a separator.
sed "s|$1|$2|" "$3" >"$3.tmp"

>
> type_sigbase="/vobs/rbs/sw/blibss_1/blibss/blibcedtsyslu/external_src/
> -I /vobs/rbs/sw/blibss_1/blibss/blibsigbasendlu/src/"
>
> find . -type f -maxdepth 1 -name '*sig.sh' |
> while read file
> do
> echo "Processing $file ...."
> search_replace /vobs/rbs/sw/rbssw_architect/rbsmdlu/
> ${type_sigbase} $file

"$type_sigbase" "$file"


> cat "$file.tmp" >"$file"
> rm -f -- "$file.tmp"


mv "$file.tmp" "$file"

> done
>



--
Hark ye, Clinker, you are a most notorious offender. You stand convicted of
sickness, hunger, wretchedness, and want.
-- Tobias Smollet
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com