Results 1 to 2 of 2
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 .
# vi sedclock.sh
...
- 11-22-2008 #1Linux Newbie
- Join Date
- Feb 2007
- Posts
- 248
sed: -e expression #1, char 24: unknown option to `s'
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 .
# vi sedclock.sh
#!/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
- 11-22-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
The problem is that you're using the slash(/) as the delimiter for sed's 's' command and there's a slash in the text which sed sees as a delimiter. Try using a different delimiter like '|'.
Code:sed 's|'$TIMEZONE'|TIMEZONE="Etc/GMT-5"|g'


Reply With Quote