Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

ksh: string handling using ${parameter%pattern} or a other option

Valued Contributor

ksh: string handling using ${parameter%pattern} or a other option

hello,

 

i have a string , seperated by "/" . i want the value from the middle of the text  ( bbb ). i tried to use ${parameter%pattern} or ${parameter#pattern} . but i need 3 steps . better option ?

 

example:

 

STR="/<aaa>/bbb/<ccc>"

HSTR=$( echo ${STR%/*} ) # /<aaa>/bbb

echo ${HSTR##/*/}        # bbb

or  a shorter command :

echo ${STR} | awk -F"/" '{ print $3}' # bbb

 

other possible commands are "sed" or "expr" .

 

kind regards

2 REPLIES
Honored Contributor Honored Contributor

Re: ksh: string handling using ${parameter%pattern} or a other option

 
Acclaimed Contributor Acclaimed Contributor

Re: ksh: string handling using ${parameter%pattern} or a other option

>but I need 3 steps.

 

Why do you care if it is three steps?  They are shell builtins and awk and sed aren't.