cancel
Showing results for 
Search instead for 
Did you mean: 

sed help require

SOLVED
Go to solution
Maaz
Valued Contributor

sed help require

I want to replace the value of a variable 'TIMEZONE' with the other string, for that I tried to use 'sed', but no success, please help .

#!/bin/bash
CLOCK=/etc/sysconfig/clock
TIMEZONE=$(grep ^TIMEZONE $CLOCK)

if [ $TIMEZONE != TIMEZONE=\"Etc/GMT-5\" ]; then
cp $CLOCK /tmp/clock
cat /tmp/clock | sed 's/'$TIMEZONE'/TIMEZONE="Etc/GMT-5"/g' > $CLOCK
fi

# bash -x sedclock.sh
+ CLOCK=/etc/sysconfig/clock
++ grep '^TIMEZONE' /etc/sysconfig/clock
+ TIMEZONE='TIMEZONE="Etc/GMT-4"'
+ '[' 'TIMEZONE="Etc/GMT-4"' '!=' 'TIMEZONE="Etc/GMT-5"' ']'
+ cp /etc/sysconfig/clock /tmp/clock
+ cat /tmp/clock
+ sed 's/TIMEZONE="Etc/GMT-4"/TIMEZONE="Etc/GMT-5"/g'
sed: -e expression #1, char 24: unknown option to `s'

Regards
2 REPLIES
Steven Schweda
Honored Contributor
Solution

Re: sed help require

Just looking, not trying anything, I'd say
that using "/" as the delimiter in your "sed"
"s" command is not a good idea when your
strings contain "/" characters. Something
like this might be closer:

sed -e 's|'$TIMEZONE'|TIMEZONE="Etc/GMT-5"|'


You really think that the "g" is needed?
Maaz
Valued Contributor

Re: sed help require

Thanks for nice help Steven Schwada