0

I have this command which works well to give me a list of ip address, MAC address, and Mac Vendor

sudo nmap -sn 192.168.0.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print " "substr($0, index($0,$3)) }' | sort

All I want to do is to add a comma as a delimeter between each of the three fields and sort the ip address column by the last octet of the ip address. By changing the command as follows I can get a comma between 1rst and 2nd column and can sort by ip address. Now I just need a comma between 2nd and 3rd column. How to add the last comma?

sudo nmap -sn 192.168.0.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print ","substr($0, index($0,$3)) }' | sort -t . -k 4,4n

1 Answer 1

0

I think you're looking for the "OFS" setting of awk (Output Field Separator, I think).

echo "one two three" | awk '{ OFS=", "; print $1,$2,$3}'
one, two, three

Also, your question would be more suitable for PowerUser or some other Stack Exchange site.

1
  • Thanks Bob, did not quite work. I will post in a different forum.
    – William K
    Mar 11, 2019 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .