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
William K
  • 1
  • 1

1 Answers1

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.

DictatorBob
  • 1,644
  • 11
  • 15