Home » Infrastructure » Unix » Shell script to get rid the " - " on a string! how?
Shell script to get rid the " - " on a string! how? [message #128078] Thu, 14 July 2005 20:31 Go to next message
azoldman
Messages: 2
Registered: July 2005
Location: Phoenix
Junior Member
Hi, I'm writting a simple shell script that can do the following thing:

$strA = abc-def, and my question is how to loop the string till it reaches the " - ", then save the "def" as a new string, $strB = def

Thanks all,

Sun
Re: Shell script to get rid the " - " on a string! how? [message #128093 is a reply to message #128078] Fri, 15 July 2005 00:46 Go to previous messageGo to next message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
$ export strA=abc-def
$ echo $strA
abc-def
$ export strB=`echo $strA | cut -d"-" -f2`
$ echo $strB
def


Best regards.

Frank
icon7.gif  Re: Shell script to get rid the " - " on a string! how? [message #128124 is a reply to message #128078] Fri, 15 July 2005 04:32 Go to previous messageGo to next message
azoldman
Messages: 2
Registered: July 2005
Location: Phoenix
Junior Member
Thanks for your quick replied, Frank!!

May be I didn't state my question clearly in which the $strA could be "abcdef-ghijk" or "abcdefghij-klmnop", etc , so I'm looking for a way that could do some looping till it reaches
" - " ( no idea where the " - " appear on the $strA ), and save whatever comes after " - " into the $strB.

$strA = abcdef-ghijk
$strB = ghijk

or

$strA = abcdefghij-klmnop
$strB = klmnop


Best Regards,

Sun

Re: Shell script to get rid the " - " on a string! how? [message #128173 is a reply to message #128124] Fri, 15 July 2005 09:41 Go to previous message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
Just try it!

Best regards.

Frank
Previous Topic: pw-syscall problem on AIX 5.1
Next Topic: Accessing SQL session from UNIX shell script
Goto Forum:
  


Current Time: Mon Nov 25 21:29:55 CST 2024