Operating System - HP-UX
1753396 Members
7391 Online
108792 Solutions
New Discussion

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

 
support_billa
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 2
Steven Schweda
Honored Contributor

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

 
Dennis Handly
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.