Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing lines with sed 2

Status
Not open for further replies.
Apr 6, 2001
1,052
CA
problem .... file with lines in the form of :

TAG_NAME="value1 value2 value3"

and i want to replace the line with:

TAG_NAME="value1 value2 value4 value5 value6"

(note the spaces and the quotes)

i can parse things out such that i have and var $ENV1 with
value1 value2 value3

in it and var $ENV2 with
value1 value2 value4 value5 value6
in it

I have tried a number of variants with sed that don't seem to work

sed -i 's/${ENV1}/${ENV2}/g' $CFGFILE
sed -i 's/'${ENV1}'/'${ENV2}'/g' $CFGFILE

i have also tried the /c change command
and i think its the spaces that are screwing me up.
i and not getting any errors, just the change is not happening.
is sed the right tool to be trying this with?
 
yes that actually comes back with an error

sed: -e expression #1, char 20: unterminated `s' command
 
What are the REAL values of ENV1 and ENV2 ?
No / inside ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Code:
FW_SERVICES_EXT_TCP="5801 5901 ssh"
 
-> ENV1=5801 5901 ssh

FW_SERVICES_EXT_TCP="5801 5901 buyguide ftp homedyn http prismmas prismsc prismsh prismxs prismxw ssh xdmcp xscomm"

-> ENV2=5801 5901 buyguide ftp homedyn http prismmas prismsc prismsh prismxs prismxw ssh xdmcp xscomm
 
How do you assign ENV1 and ENV2 in your script ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
note $SID is set elsewhere and may be null
Code:
#################################################################
# Poke some holes in the firewall for database socket connections
CFGFILE=/etc/sysconfig/SuSEfirewall2
ORGPATTERN=`cat $CFGFILE | grep "^FW_SERVICES_EXT_TCP="` 
EXISTINGHOLES=`cat $CFGFILE | grep "^FW_SERVICES_EXT_TCP=" | cut -d\" -f2`
rm -f /tmp/holes.$$
#echo "Existing Holes = " $EXISTINGHOLES
for j in $EXISTINGHOLES
do
    echo $j >> /tmp/holes.$$
done
for i in prismmas prismsc prismsh prismxs prismxw xscomm buyguide homedyn homestat
do
    echo $i$SID >> /tmp/holes.$$
done
#echo "New Holes = " `cat /tmp/holes.$$`
NEWHOLES=`cat /tmp/holes.$$ | sort -u`
rm -f /tmp/holes.$$
sed -i 's/'${EXISTINGHOLES}'/'${NEWHOLES}'/g' $CFGFILE
#################################################################
 
Replace this:
NEWHOLES=`cat /tmp/holes.$$ | sort -u`

with this:
NEWHOLES=`sort -u /tmp/holes.$$ | tr '\n' ' '`

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thx guys that now worked with the

NEWHOLES=`sort -u /tmp/holes.$$ | tr '\n' ' '`
and
sed -i "s/${ENV1}/${ENV2}/g" $CFGFILE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top