I have a variable that is populated from a log file. it is capturing the host name of a server for use in the awk printout. im making a CSV file that prints the MAC address, port number then the host name.
here is that variable
hostVar=$(awk '/#/' macAddress.log)
this works fine what I need is to print the variable in my next awk statement so that it prints the var last. below works fine and prints MAC,HOST
grep -Ff masterList macAddress.log | awk '{print $2 "," $4}' >> output.csv
I am using a master list to filter out the MAC addresses I need to capture. the end result needs to look like this MAC,PORT,HOST
grep -Ff masterList.csv macAddress.log | awk '{print $2 "," $4 "," $hostVar}' >> output.csv
obviously that doesnt work but I need the host name in the CSV file next to the port number (MAC then port num then host name)
0011.2233.4455,Gi1/0,Switch1
(switch1 being what $hostVar is populated with)