I have 2 csv files. File1 is an existing list of private IP address & its hostname. File2 is a daily report which has 8 columns in which 2 containing the private IP. I want to compare file2 with with file1 by matching field 4 and field 7 of file2 with field 2 of file1. Then, upon matching, I want to append field 3 and field 6 of file2 according to the matches of field 4 and field 7 with field 2 of file1.
File1.csv
PC1,192.168.3.1
PC2,192.168.3.2
PC3,192.168.3.3
File2.csv (Has about 50 lines)
Port,Type,S_Host,S_IP,Port,D_Host,D_IP,Port
2,tcp,N/A,192.168.3.1,2,N/A,192.168.3.2,8
3,tcp,N/A,192.168.3.2,2,N/A,192.168.3.3,3
I need to do a bash script to automate file2.
Desired output:
Port,Type,S_Host,S_IP,Port,D_Host,D_IP,Port
2,tcp,PC1,192.168.3.1,2,PC2,192.168.3.2,8
3,tcp,PC2,192.168.3.2,2,PC3,192.168.3.3,3
join
command. – Digvijay Sawk
(indexed by IP) then process file2 and lookup the hostname using the IP from fields 4 & 7 and set fields 3 & 6 equal to the resulting hostnames and print the record. – David C. Rankin