Operating System - HP-UX
1827295 Members
2543 Online
109717 Solutions
New Discussion

How to make substring without using a function?

 
SOLVED
Go to solution
Fragon
Trusted Contributor

How to make substring without using a function?

For example:
str1="WindowsIsVeryHard"
str2="WindowsIsVery"
I want to make str3=$str1-$str2,that's "Hard"!
How to do?
Thanks a lot!
4 REPLIES 4
Chris Wilshaw
Honored Contributor

Re: How to make substring without using a function?

I suppose it depends on what you're trying in, but at a normal shell prompt;

str1="WindowsIsVeryHard"
str2="WindowsIsVery"

str3=`echo $str1 | sed -e s/$str2//g`


echo $str3
Hard

Chris
Jean-Louis Phelix
Honored Contributor
Solution

Re: How to make substring without using a function?

Hi,

hp> A=abc
hp> B=ab
hp> echo ${A##$B}
c

See man sh-possix for more details.

Regards.
It works for me (© Bill McNAMARA ...)
john korterman
Honored Contributor

Re: How to make substring without using a function?

Hi,
in korn shell you can do this, but it is hard to tell whether or not it is a function:
# str1="WindowsIsVeryHard"
# str2="WindowsIsVery"
# echo ${str1##$str2}

regards,
John K.
it would be nice if you always got a second chance
Fragon
Trusted Contributor

Re: How to make substring without using a function?

Thank you all!
To Chris: Very sorry I give 10 points to all but it's strange that you only get 5 ...
Thank you for you help anyway!