ksh: string handling using ${parameter%pattern} or a other option (154 Views)
Reply
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 1 of 3 (154 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

Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,074
Registered: ‎02-23-2005
Message 2 of 3 (140 Views)

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

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,849
Registered: ‎03-06-2006
Message 3 of 3 (127 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.

Please use plain text.
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