Results 1 to 4 of 4
I have a variable saying $remaining having value as "/etc /var /sns /vol"(which is assigned at runtime)
i want to check whether '/sns' is present in that string. If yes, ...
- 07-26-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 5
how to remove a particular word from a string in Shell scripting
I have a variable saying $remaining having value as "/etc /var /sns /vol"(which is assigned at runtime)
i want to check whether '/sns' is present in that string. If yes, it should be removed and then the string must be like $remaining="/etc /var /vol"
is there any command available to check for particular substring and remove that.
Plz help.Thnx in advance
- 07-26-2007 #2RegardsCode:
remaining="/etc /var /sns /vol" remaining=`echo $remaining | sed "s/\/sns //g"`
- 07-26-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Also for bash:
producing:Code:#!/bin/sh # @(#) s1 Demonstrate bash pattern matching in variable contents. set -o nounset echo echo "GNU bash $BASH_VERSION" >&2 echo remaining="/etc /var /sns /vol" echo " variables remaining = :${remaining/??sns/}:" exit 0
(with help from O''Reilly Learning the bash Shell, 2nd, pages 99 ff) ... cheers, drlCode:% ./s1 GNU bash 2.05b.0(1)-release variables remaining = :/etc /var /vol:
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 09-06-2007 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 5
thank you bird man and Drl


Reply With Quote