Re: Subtrating strings ... (abcd) - (abc) = d ...
am 03.10.2007 22:36:56 von cfajohnson
On 2007-10-03, rohitsagar@yahoo.com wrote:
> I have two strings
>
> string 1="abcd"
> string 2="abc"
>
> I want subtraction of two strings = "d"
>
> Another example
>
> string 1="computers"
> string 2="comp"
>
> I want subtraction of two strings = "uters"
In bash or ksh93:
string1=abcd
string2=abc
string3=${string1/"$string2"/}
Otherwise:
printf "%s\n" "$string1" | sed "s/$string2//"
If $string2 contains slashes, they must be escaped, or use a
different sed delimiter.
--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Re: Subtrating strings ... (abcd) - (abc) = d ...
am 03.10.2007 22:37:59 von cichomitiko
rohitsagar wrote:
> I have two strings
>
> string 1="abcd"
> string 2="abc"
>
> I want subtraction of two strings = "d"
>
>
>
> Another example
>
> string 1="computers"
> string 2="comp"
>
> I want subtraction of two strings = "uters"
[...]
$ s1="computers"
$ s2="comp"
$ printf "%s\n" "${s1#$s2}"
uters
Dimitre