Extracting part of the basename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting part of the basename
# 1  
Old 02-13-2007
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  
Old 02-13-2007
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  
Old 02-13-2007
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  
Old 02-13-2007
Yes,
see this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting the part of string

I have a string: 2015-04-16 07:30:05,625000 +0900 xxxx.com I just want to extract the time from the above line I am using the below syntax x=~ /(.*) (\d+)\:(\d+)\:(\d+),(.*)\.com/ $time = $2 . ':' . $3 . ':' . $4; print $time But it is not working. Can some1 please help (2 Replies)
Discussion started by: karan8810
2 Replies

2. Shell Programming and Scripting

Extracting a part of a string

Hi, I needed to extract some specific characters from a string based on user input. For example: After the script executes the user enters the following details: Please enter the string: This is a shell script Please enter the starting position: 11 Please enter the number of characters to be... (4 Replies)
Discussion started by: ChandanN
4 Replies

3. UNIX for Dummies Questions & Answers

Extracting part of a word

I have the code message={TP=2012:09:23:00:00:00:GMT,SD=2012:09:23:00:00:00:GMT,SP=2,FT=CCGT,FG=3605} I want to extract the FG=3605 parts of this. Please help. I am trying to do this using awk or unix. (5 Replies)
Discussion started by: JenniferTopham
5 Replies

4. Shell Programming and Scripting

Extracting part of line between two words

Hi, I have a file few hundred MB's with text like one below in single line. 20091117 abc xyg 20091117 def ghi 20091118 ppp ttt 20091118 zzz zzz xxx I need to extract part of line from 1st occurence of pattern 20091117 till first occurence of another pattern 20091118. I tried... (3 Replies)
Discussion started by: artistic94555
3 Replies

5. Shell Programming and Scripting

extracting basename in awk or nawk

I am having a hard time extracting the file name from the above code. Instead of printing /folder/file.1$.5$, I would like it to print the file name file.1$.5$. I have tried using basename but it looks like NAWK or AWK does not recognise basename. Each time I type it in, it prints out the word... (4 Replies)
Discussion started by: asemota
4 Replies

6. Shell Programming and Scripting

extracting part of a text file

Hi guys So I have a very large log file where each event is logged along with the time that it occurred. So for e.g. The contents of the file look like: ... 12:00:07 event 0 happened. 12:01:01 event 1 happened. 12:01:05 event 2 happened. 12:01:30 event 3 happened. 12:02:01 event 4... (10 Replies)
Discussion started by: alinaqvi90
10 Replies

7. Shell Programming and Scripting

Extracting email address using basename

Is it possible to use a variable as the delimiter using basename? I have a num variable that will be changing in the filename now. The files could looke like this my.email.address@mydomain.com.VL010600_474 my.email.address@mydomain.com.VL020600_474... (2 Replies)
Discussion started by: Drenhead
2 Replies

8. Shell Programming and Scripting

awk: Extracting part of the buffer

Hi, I am trying to extract part of a line using "awk". My requirement is to extract the value $6 (which is the last parameter) from a line. As the sixth value contains some space, i am getting only part of the string. so i am trying to extract from $6 to the end of the buffer. How to do it... (7 Replies)
Discussion started by: venkat_k
7 Replies

9. Shell Programming and Scripting

need help extracting this part

JADE TRADER 143W MYPEN 40 HC M X10 28 7 1 0 MYPEN 20 GP X X10 15 2 1 0 MYPEN 40 GP X X10 28 7 1 0 MYPEN 20... (6 Replies)
Discussion started by: finalight
6 Replies

10. Shell Programming and Scripting

Extracting part of a string

Hi all, I have to extract only the second part of a database column (VARCHAR) and the value is seperated by a "~" xyz~ chxyz36r~ abder~000082685 mnops~000083554 fulfil302~00026 Above are some examples of the values and for each record I have to extract the value after "~" , if there is a... (8 Replies)
Discussion started by: sam_78_nyc
8 Replies
Login or Register to Ask a Question