ksh: string handling using ${parameter%pattern} or a other option (227 Views)
Reply
Valued Contributor
Posts: 192
Registered: ‎06-27-2011
Message 1 of 3 (227 Views)

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

Honored Contributor
Posts: 9,119
Registered: ‎02-23-2005
Message 2 of 3 (213 Views)

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

Acclaimed Contributor
Posts: 25,666
Registered: ‎03-06-2006
Message 3 of 3 (200 Views)

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.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.