The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Listing files with full path r_sethu UNIX for Dummies Questions & Answers 5 2 Weeks Ago 02:56 AM
List files with full path mr_bold Shell Programming and Scripting 3 10-07-2008 12:19 PM
to find the file with full path surjyap Shell Programming and Scripting 5 01-18-2008 02:26 PM
getting full path from relative path polypus Shell Programming and Scripting 4 03-25-2007 12:08 PM
Full path of executing script in ksh? BriceBu Shell Programming and Scripting 2 09-19-2005 09:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-06-2008
Registered User
 

Join Date: Oct 2008
Posts: 1
Replace a filename with full path using sed

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...

i even tried awk, but didn't work either

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

thanks
AK
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-06-2008
cfajohnson's Avatar
Shell programmer, author
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 1,972
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
Reply With Quote
  #3 (permalink)  
Old 10-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 38
Very simple to use SED here:

Code:
sed '/-d\/data/c\
-d/dev/vx/rdsk/sandg-100/raw200-01 \\
' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 06:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66