grep the result of some Command(eg. netstat -apn)
<p>When you want to know which port was already in use you can use <code>netstat -apn | grep 27777</code>. The result is below:  </p>

<pre><code>&gt; tcp        0      0 ::ffff:43.69.96.68:27777    :::*       LISTEN  79339/java
</code></pre>

<p>Then you can find which process use the PID 79339.</p>

<pre><code>ps -aux | grep 79339
</code></pre>

<p>Now I wonder if there is a command to find which process uses the port that was already in use.</p>

<p>I tried <code>ps -aux | grep netstat -apn | grep 18888 | awk -F '[ /]+' '{print $7}'</code>
but it is no working.</p>