Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NETSTAT result format 1

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I need to obtain the results of a NETSTAT command in unix into a excel file.. NETSTAT is currently outputting the fwg:
tcp 0 0 local.56455 localhost.7500 ESTABLISHED
tcp 0 0 local.80 hpunx.7500 ESTABLISHED

I need to obtain the Origin address, Origin Port, dest addr and dest port in separate columns..

can anyone pl help ?

thnx
 
Code:
BEGIN {
  FS="( *)|([.])"
  OFS=","
}
{
  print $4,$5,$6,$7
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
hi,

thnx for the response. I put the code above in a file called test.awk and executed the fwg cmd:
$> netstat | test.awk > test2.xls

and got the fwg error:
Syntax error at line 5 : `}' is not expected.

any suggestions ?

thnx
 
yeah,.......

either

netstat | nawk -f test.awk > test2.xls

or

put '#!/bin/nawk -f' as the first line in your test.awk AND 'chmod 755 test.awk'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
thnx again..

I am allmost there.. just 1 more problem.. There exists desitnation addresses like "ptdec29.teleco.com.3340" or

tcp 0 0 local.56455 localhost.7500 ESTABLISHED
tcp 0 0 loc.80 ptdec29.teleco.com.7500 ESTABLISHED

So, the script print ptdec29 in the destination column and "teleco" in the port column ! how do I put the entire string "ptdec29.teleco.com" in the dest column ?

thnx,
 
Code:
BEGIN {
  OFS=","
}

function rindex(str)
{
  match(str,"\.[^.]*$")
  return RSTART
}

{
  print substr($4, 1, rindex($4)-1),  substr($4, rindex($4)+1), substr($5,1, rindex($5)-1),  substr($5, rindex($5)+1)
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top