May 8, 2006 #1 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location IN Hi, I want to filter a string in my script.String is: (cRanjan_abc_xyz@foo.com) I want to print only cRanjan_abc.Can anyone give me some pointers regarding this. Regards, Ranjan.
Hi, I want to filter a string in my script.String is: (cRanjan_abc_xyz@foo.com) I want to print only cRanjan_abc.Can anyone give me some pointers regarding this. Regards, Ranjan.
May 8, 2006 1 #2 columb IS-IT--Management Joined Feb 5, 2004 Messages 1,231 Location EU Try Code: print $(expr $string : "\([^_]*_[^_]*\).*") Although I'm sure the awk/sed gurus will have other answers Ceci n'est pas un signature Columb Healy Upvote 0 Downvote
Try Code: print $(expr $string : "\([^_]*_[^_]*\).*") Although I'm sure the awk/sed gurus will have other answers Ceci n'est pas un signature Columb Healy
May 8, 2006 #3 bigoldbulldog Programmer Joined Feb 26, 2002 Messages 286 Location US sed '/cRanjan_abc_xyz@foo.com/!d;s/_[^_]*$//' Cheers, ND [small]bigoldbulldog AT hotmail[/small] Upvote 0 Downvote
May 8, 2006 #4 SkiLift Programmer Joined Dec 18, 2003 Messages 47 Location US The 'cut' command is underrated: echo "cRanjan_abc_xyz@foo.com" | cut -d\@ -f1 Upvote 0 Downvote
May 8, 2006 #5 p5wizard IS-IT--Management Joined Apr 18, 2005 Messages 3,165 Location BE Only thing is, _xyz part needs to be cut off. So echo $email|cut -d_ -f1-2 might do. HTH, p5wizard Upvote 0 Downvote
May 8, 2006 #6 SamBones Programmer Joined Aug 8, 2002 Messages 3,186 Location US Try this... Code: $ EMAILADDR=cRanjan_abc_xyz@foo.com $ FIRSTPART=${EMAILADDR%_*} $ print $FIRSTPART [blue]cRanjan_abc[/blue] Upvote 0 Downvote
Try this... Code: $ EMAILADDR=cRanjan_abc_xyz@foo.com $ FIRSTPART=${EMAILADDR%_*} $ print $FIRSTPART [blue]cRanjan_abc[/blue]