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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed to replace text with a variable orahi001 UNIX for Dummies Questions & Answers 1 03-06-2008 05:25 PM
replace with value of variable using SED prvnrk Shell Programming and Scripting 2 01-13-2008 07:13 AM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 07:56 PM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 11:56 AM
Find and replace the value in a variable aajmani Shell Programming and Scripting 5 09-21-2005 04:52 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: May 2005
Posts: 5
How to partially replace variable value?

I have variable $2 whose value is expdp_SDW_MSTR_VMDB.par
I want to replace three characters from right (par) with (log)

Input --> expdp_SDW_MSTR_VMDB.par
Output --> expdp_SDW_MSTR_VMDB.log

Thanks
Deep
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-11-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,494
Code:
var=expdp_SDW_MSTR_VMDB.par
newname=${var%%par}log
Reply With Quote
  #3 (permalink)  
Old 06-12-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 533
Wink Another approach

Note the use of the $ with the par$ in the sed command; this means to grab the text at the end of a line. Hence, the command did not change the par earlier in the text string.

Code:
> var=expdp_par_SDW_MSTR_VMDB.par
> var2=$(echo $var | sed "s/par$/log/")
> echo $var2
expdp_par_SDW_MSTR_VMDB.log
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0