How do i get all the values ?

Hello All

These are diffrent columns in my fingerprinting tool.Look at code lines pls.

DUP

/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|sed -n '2,$p'|awk '{print $1$2}'

Protocol

echo "udp"

Local IP

A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')

B=`echo "$A"|grep "*"|wc -l`

if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f1`
echo "$C"
fi

if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f1-4`
echo "$D"
fi

Local Port

A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')

B=`echo "$A"|grep "*"|wc -l`

if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f2`
echo "$C"
fi

if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f5`
echo "$D"
fi

Remote IP

echo "NULL"

Remote Port

echo "NULL"

State

A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $2}')

echo "$A"

Issue:

Above lines have been written to get all UDP data in a CSV.

e.g

bash-3.00$ /usr/bin/netstat -an -f inet -P udp

UDP: IPv4
   Local Address        Remote Address      State
-------------------- -------------------- ----------
      *.48517                             Idle
      *.*                                 Unbound
      *.161                               Idle
      *.111                               Idle
      *.*                                 Unbound
      *.33270                             Idle
      *.*                                 Unbound
      *.*                                 Unbound
      *.33271                             Idle
      *.4045                              Idle
      *.5000                              Idle
      *.5000                              Idle
      *.5000                              Idle

When i run the code,it fumbles up at these three lines

      *.5000                              Idle
      *.5000                              Idle
      *.5000                              Idle

because both colmuns in all 3 rows are identical.

How can i modify code lines to capture all three rows as it is?

I am facing same issue for capturing data for TCP

/usr/bin/netstat -an -f inet -P tcp

I want the commands data as it is in my CSV ,without losing any of it?

Kindly advice.

Regards
Abhi

You are using "uniq" in your pipeline.

If you need it for some other reason (sorry, too much stuff to look at up there!) you need to do something to modify those kinds of lines before they hit "uniq" and (if necessary) undo the changes after.

By the way, "sort -u" eliminates "sort | uniq".

i was trying 'sort|uniq' just for R&D.....

i am not suppose to use it as i would be losing data (even if its identical)..

thanks for 'sort -u' !!

Regards
Abhi

/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|sed -n '2,$p'|awk '{print $1$2}'

Can be changed to:

/usr/bin/netstat -an -f inet -P udp|awk 'NR>1 && ! (/UDP/||/Local/||/--/)  {print $1$2}'

thanks for 'awk' !!

though i am still stuck at the same problem.I am unable to get all the values seen ,as it is,in the CSV.

Regards
Abhi

please show sample of your csv file, and the desired output.

well...it worked !!

initially i had copied 'awk' statement of yours into code lines for all columns...it did not work...and then i kept it only in DUP column and used 'sort -u' in rest of the columns and bingo !!

i am now able to capture all identical rows as well....

thanks again !!

Regards
Abhi