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
need help extracting this part finalight Shell Programming and Scripting 6 05-20-2008 06:03 AM
Using find command with awk or basename sam_78_nyc Shell Programming and Scripting 4 11-05-2007 07:49 PM
Extracting part of a string sam_78_nyc Shell Programming and Scripting 8 04-25-2007 07:37 PM
reverse of basename braindrain Shell Programming and Scripting 7 10-03-2006 02:24 AM
extracting uncommon part between two files sabyasm Shell Programming and Scripting 2 11-06-2005 01:25 PM

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 02-13-2007
madhunk madhunk is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 91
Extracting part of the basename

Hi,

I was wondering if there is an easy way to strip off the required basename. I have a script called apb0110021.sh and the contents of the script are

Code:
typeset -u MScript=`basename $0 | cut -d. -f1`
scriptname=sys.Audit.ksh
parms="PROJECT1 dsAudit $MScript 1 BEGIN"
$SCRIPTS/$scriptname $parms
Basically, I am using typeset -u to capitalize the words and extracting the apb0110021 as $MScript.

Change required: After a code review, the script name has to be changed to sys.mrch_mart_apb0110021.sh. Though the script name changes, I would still have to extract only the apb0110021 and pass it as one of the parameters.

Is there an quick turn around solution to this without involving a lot of code change?

Please advice.
Madhu
  #2 (permalink)  
Old 02-13-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
typeset -u MScript="${0%.*}"
scriptname="sys.Audit.ksh"
parms="PROJECT1 dsAudit ${MScript##*_} 1 BEGIN"
"$SCRIPTS"/"$scriptname" "$parms"

Or with ksh93:

Code:
typeset -u MScript="${0:$((${#var}-13)):10}"
scriptname=sys.Audit.ksh
parms="PROJECT1 dsAudit $MScript 1 BEGIN"
"$SCRIPTS"/"$scriptname" "$parms"
  #3 (permalink)  
Old 02-13-2007
madhunk madhunk is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 91
Thank You Radoulov....I used the first part and it did work.

Would you please tell me what
Code:
"${0%.*}"
and
Code:
${MScript##*_}
mean by.

I would really appreciate that.
  #4 (permalink)  
Old 02-13-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Yes,
see this
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 03: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