If i execute the below comment, The result will be like this 8060 0.0.0.0
netstat -antup | grep nginx |awk ‘{print $4 "t" $5 }’ | cut -d ":" -f2
But I want the result to be like this 8060
If i execute the below comment, The result will be like this 8060 0.0.0.0
netstat -antup | grep nginx |awk ‘{print $4 "t" $5 }’ | cut -d ":" -f2
But I want the result to be like this 8060
2
Answers
Not sure what the orignial response from the command is, but just cut the response again is one way
Deconstructing the command you provided,
netstat -antup
prints these information:You want just the "8060", which is the port, nginx is listening to.
The next part was fine.
grep nginx |awk '{print $4}'
gives you the corresponding Local Address. You don’t need the"t" $5
part, as the Foreign Address is not relevant here.The intermediary result should look like this:
Now the port ist the last part after a ":". Be aware, that IPv6 addresses also contain ":"s. So i’d suggest to cut the very last one instead of the 2nd.
You can do so, by reverting the output, cutting the first bit and reverting again:
et voila. the desired output