Computing.Net > Forums > Unix > Problem with SED

Problem with SED

Reply to Message Icon

Original Message
Name: sting013
Date: March 15, 2006 at 07:22:13 Pacific
Subject: Problem with SED
OS: Sun
CPU/Ram: ?
Model/Manufacturer: ?
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


Report Offensive Message For Removal


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

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

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


Luke Chi


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: Problem with SED

Comments:

 


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




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge