title: Seperate IP from port in CSV file using sed/awk
body: <p>I am using following to create a csv with the output as shown below. Now, from the output csv I want to split the ip address and port names in different columns and display only process id in last column.</p>
  
  <p>Script is:-</p>
  
  <pre><code>netstat -anputw |  awk '{if ($1 == "tcp") print $1,",",$4,",",$5,",",$6,",",$7}' &gt; $HOME/MyLog/connections_$HOSTNAME.csv
  netstat -anputw |  awk '{if ($1 == "udp") print $1,",",$4,",",$5,",",",",$6}' &gt;&gt; $HOME/MyLog/connections_$HOSTNAME.csv
  </code></pre>
  
  <p>Output in CSV is like:-</p>
  
  <pre><code>tcp      127.0.0.1:25    0.0.0.0:*   LISTEN      1112/sendmail
  tcp      192.168.0.38:22     192.168.10.143:62998    ESTABLISHED     3084987/sshd
  </code></pre>
  
  <p>Now, I wish to split ip address and ports (comma seperated) and from last column, trim the text and display only process id. Lastly, the first column for this CSV should be the IP address of the host name of which the script is run(displayed for each of the rows). So, output will be like below:-</p>
  
  <pre><code>192.168.0.22  tcp  127.0.0.1     25  0.0.0.0         *       LISTEN        1112
  192.168.0.22  tcp  192.68.0.38   22  192.168.10.143  62998   ESTABLISHED   3084987
  </code></pre>
  
  <p>Any pointers how can I achieve this in the csv output?</p>