find words with grep....

I have a .txt file which contains several lines of text. I need to write a script program using grep or any other unix tool so as to detect part of the text (words) between / / that begin with the symbol ~.
For example if somewhere in the text appears a webpage address like
http://www.cs.may.ie/~dtray/cs211/lecture1.htm,
my program must print only the word dtray (the symbol ~ must be ommited)

Is this a homework assignment?

I would grep lines containing the keywords, and pipe to a cut.

care to provide an example?

well...what are the rules/conditions? Will every url be complete as submitted above?

well..... that I don't know - we better ask the OP.

but how about these simple samples:

http://www.cs.may.ie/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/foo/bar/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/foo/~bar/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/~foo~dtray/cs211/lecture1.htm

how would you do it with grep/cut?

"http://www.cs.may.ie/~foo~dtray/cs211/lecture1.htm" <==what?

Ok, I give up. How to differentiate whether you want the first tilde, or the nth.

well...... assuming OP's explanation...... I'd expect 'foo~dtray' as the output.

I think this will do the trick..but whats the requirements is..still not sure about..
sed -e 's/[^~]*\/\(~[^/]*\).*/\1/' data2