Computing.Net > Forums > Unix > Problem with SED

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Problem with SED

Reply to Message Icon

Name: sting013
Date: March 15, 2006 at 07:22:13 Pacific
OS: Sun
CPU/Ram: ?
Product: ?
Comment:

Hello All
I'm having a little problem using SED. I can get the SED command to work on the command line but not in a script below is the script I'm using.

#!/usr/bin/ksh

logfile=/var/adm/messages.1
searchlog=/monitor/nagios/scripts/MESSAGE.txt

if [ ! -e $searchlog ]
then
head -1 $logfile | cut -d'[' -f1|read VAR1
echo "VAR1 = "$VAR1
echo "$VAR1" | cut -d" " -f5|read VAR2
echo "VAR2 = "$VAR2
if [[ $VAR2 = /* ]]
then
echo "VAR1 THEN = "$VAR1
VAR3=`echo $VAR1 | sed 's/\//\\\//g'`
# echo "$VAR3" > $searchlog
echo "VAR3 = "$VAR3
# echo "IN THEN"
else
# echo "$VAR1" > $searchlog
echo "VAR1 = "$VAR1
echo "IN ELSE"
fi
fi
echo "Out Of Loop"

This is the output I'm getting.
VAR1 = Feb 24 10:24:18 /usr/lib/snmp/snmpdx:
VAR2 = /usr/lib/snmp/snmpdx:
VAR1 THEN = Feb 24 10:24:18 /usr/lib/snmp/snmpdx:
sed: command garbled: s/\//\\//g
VAR3 =
Out Of Loop

Also here is what I get when I set VAR3 to /usr/lib/snmp/snmpdx:
and run this command echo $VAR3 | sed 's/\//\\\//g'
below is the output.
\/usr\/lib\/snmp\/snmpdx:

I have no clue way this is not working any help would be great.
Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: lchi2000g
Date: March 29, 2006 at 11:57:18 Pacific
Reply:

replace: (single quotes)
VAR3=`echo $VAR1 | sed 's/\//\\\//g'`

with: (double quotes)
VAR3=`echo $VAR1 | sed "s/\//\\\//g"`


Luke Chi


0
Reply to Message Icon

Related Posts

See More


Uuencode problem in mail ... convert lowercase to uppe...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Problem with SED

Problem with sed www.computing.net/answers/unix/problem-with-sed/3990.html

sed problem with regular expression www.computing.net/answers/unix/sed-problem-with-regular-expression/6876.html

problems with sed www.computing.net/answers/unix/problems-with-sed/7174.html