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



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
KSH variable substitution tipsy Shell Programming and Scripting 5 08-14-2006 05:07 PM
Variable Substitution garak Shell Programming and Scripting 2 03-16-2006 08:55 PM
awk variable substitution apalex UNIX for Dummies Questions & Answers 1 09-10-2004 06:02 PM
variable substitution ck-18 UNIX for Dummies Questions & Answers 1 05-16-2003 08:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-11-2008
alrinno alrinno is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 18
Red face Sed variable substitution when variable constructed of a directory path

Hello,

i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.


my var1 is a string constructed like this:
filename1 filerev1 filepath1

my var2 is another string constructed like this:
filename2 filerev2 filepath2

when i do sed "s/$var1/$var2/g" inputfile i get an error stating that sed can't parse this correctly. I'm assuming its b/c the string variables contain (/) in the filepath portion... how can i get sed to treat the variable contents as a whole string without tripping up on the (/)? this string was constructed in a previous portion of my script using dirname, so trying to avoid going back and escaping each (/)... any suggestions?
thanks,

  #2 (permalink)  
Old 07-11-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink try a different format for the sed

Code:
sed "s/99998/"$jobnum"/g;" $src"j99998a.pst" > "j"$jobnum"a.pst"
changes 99998 to my stored $jobnum
starting with my j99998a.pst file (using $src as path location)
and outputting to new name with my $jobnum as the new filename

Just follow all of the double quotes to make sure variables all line up correctly.

I actually do several of these when setting up repetitive work - copying a global use file and customizing it for my current job/task. (By habit, I use 99998 as a dummy number - I found that using 99999 could run into issues since "99999" could be a mask for outputs or other uses.)
  #3 (permalink)  
Old 07-11-2008
alrinno alrinno is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 18
thanks Joeyg...

i found that you can also change the delimiter to ( : ) instead of ( / ) on sed, and desired result happens..

sed "s:$oldvar:$newvar:g"
Sponsored Links
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 02:27 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