The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-06-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,311
Quote:
Originally Posted by aksaravanan View Post
hi,

i need to replace a line a file with a new raw device location..
original file..

/opt/sybase/ASE1502/ASE-15_0/bin/dataserver \
-d/data/TST_AKS1/sybdevices/master.dat \
-e/logs/sybase/TST_AKS1/SFO_TST_AKS1.log \
-c/apps/sybase/ASE1502/ASE-15_0/TST_AKS1.cfg \
-M/apps/sybase/ASE1502/ASE-15_0 \


i need to change -d value to /dev/vx/rdsk/sandg-100/raw200-01
so new file should look like

/opt/sybase/ASE1502/ASE-15_0/bin/dataserver \
-d/dev/vx/rdsk/sandg-100/raw200-01 \
-e/logs/sybase/TST_AKS1/SFO_TST_AKS1.log \
-c/apps/sybase/ASE1502/ASE-15_0/TST_AKS1.cfg \
-M/apps/sybase/ASE1502/ASE-15_0 \

i tried using sed
i set the new file name in a varaiable

export mydev=/dev/vx/rdsk/sandg-100/raw200-01
sed s/^-d.*/$mydev/g

it didn't work..

any idea how to make work, it would be nice if i can use a shell variable inside sed command to replace the value...

Use a different delimiter when you have slashes in one of the fields:

Code:
mydev=/dev/vx/rdsk/sandg-100/raw200-01
sed "s|^-d.*|$mydev|g"
Quote:
i even tried awk, but didn't work either

awk '{ if ($1 ~= "-d") print $0 else print $mydevice }' <filename

Code:
awk -v mydev="$mydev" '/^-d/ { print mydev; next } { print }' filename