May 8, 2006 #1 ranjank IS-IT--Management May 9, 2003 176 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 Feb 5, 2004 1,231 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 Feb 26, 2002 286 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 Dec 18, 2003 47 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 Apr 18, 2005 3,165 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 Aug 8, 2002 3,186 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]