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 06-15-2009 03:56 AM
List files with full path mr_bold Shell Programming and Scripting 3 10-07-2008 01:19 PM
to find the file with full path surjyap Shell Programming and Scripting 5 01-18-2008 03:26 PM
getting full path from relative path polypus Shell Programming and Scripting 4 03-25-2007 01:08 PM
Full path of executing script in ksh? BriceBu Shell Programming and Scripting 2 09-19-2005 10:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-06-2008
aksaravanan aksaravanan is offline
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
  #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,369
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

  #3 (permalink)  
Old 10-06-2008
freelong freelong is offline
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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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