Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need String filtration help. 1

Status
Not open for further replies.

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.
 
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
 
sed '/cRanjan_abc_xyz@foo.com/!d;s/_[^_]*$//'

Cheers,
ND [smile]

[small]bigoldbulldog AT hotmail[/small]
 
The 'cut' command is underrated:

echo "cRanjan_abc_xyz@foo.com" | cut -d\@ -f1
 
Only thing is, _xyz part needs to be cut off.

So

echo $email|cut -d_ -f1-2

might do.


HTH,

p5wizard
 
Try this...
Code:
$ EMAILADDR=cRanjan_abc_xyz@foo.com
$ FIRSTPART=${EMAILADDR%_*}
$ print $FIRSTPART
[blue]cRanjan_abc[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top