2 edited tags
| link
1
source | link

How to capture the port number from this `lsof -F` output using awk (or something better)?

I've got output coming from lsof -F that looks like this:

p7646
g7646
R8300
csocat
u1000
Labe
f3
au
l
tIPv4
G0x80002;0x0
d640391
o0t0
PTCP
n*:51352
TST=LISTEN
TQR=0
TQS=0

I am trying to capture the value 51352, which is a bound port I'm interested in knowing.

I'm close in that I can get the n*:51352 value with this:

awk '/^n/ { print $1 }'

and can actually get the exact 51352 value I need with two separate awks:

awk '/^n/ { print $1 }' | awk -F':' '{print $2}'

but is there a better way, either a single-command awk or a cleaner non-awk solution?

There should only ever be one line starting with n* so I don't need to worry about handling multiple lines.