how to get the number between two signs

Hi,

I have the following problem. I want to extract only the numbers from a column with output like this one:

*:bootpc
*:ssh
192.168.0.90:42904->192.168.0.3:jabber-client
192.168.0.90:47380->192.168.0.4:3389

I looked through some of the sed commands but couldn't figure it out. The tricky part, at least for me, is to keep the *:bootpc, *:ssh, etc. and to leave only the port numbers from the rest of the stuff. Can anyone tell me how to accomplish this?

Try whether this helps

$ egrep "bootpc|ssh" fname;egrep -v "bootpc|ssh" fname | nawk -F":|-" '{ print $2}'
*:bootpc
*:ssh
42904
47380

There is a dirty method

while read line; do
$number = `cut -d: -f2  $line | cut -d- -f1`
echo $number
loop << fname

Try...

sed 's/.*:\([0-9]*\)->.*/\1/' file1

Ygor and mahendramahendr your suggestions work fine. I'm trying to implement your one Ygor but I'm printing two colums at the same time and it strips off the first one entirely. This is the ouput and it should be with the Process name before it:

Process  name  dhcpcd  on  port  *:bootpc       Number  of  files  opened  12
Process  name  sshd    on  port  *:ssh  Number  of  files  opened  23
42904   Number  of  files  opened  56
47380   Number  of  files  opened  21

Is there a way around it? Here is my source:

output()
{
   lsof -w -n -i | uniq -f 7
}

output | awk 'NR>1{print "Process name\t" $1 "\ton port\t" $8}' | sed 's/.*:\([0-9]*\)->.*/\1/' | column -t > file1.list
output | awk 'NR>1{print $2}' | while read pid; do
lsof -p $pid | wc -l | awk '{print "Number of files opened\t" $1}' | column -t 
done > file2.list

paste file1.list file2.list

change highlighted line to:

awk 'NR>1{split($8,arr,"->");print "Process name\t" $1 "\ton port\t" arr[1]}' | column -t > file1.list