perl - Find matching pattern of first columns between two files and print the line from each file in a third file -
i have 2 files 1 containing server name , ip , containing server name , machine name, example. files in no real order. have tried using variation of sort, awk, , sed. first file not maintained , contains bogus data offsets how planning on doing it.
im trying pattern match between 2 files servers contained in both lines , print data lines in both files on 1 line in thrid file.
file 1:
server1 10.10.10.1 server2 10.10.10.2 .... server154 10.10.30.8 server155 10.10.30.9
file 2:
server1 site site1 server2 site site2 .... server154 site site154 server155 site site155
output:
server1 10.10.10.1 site site1 server2 10.10.10.2 site site2 ... server154 10.10.30.8 site site154 server155 10.10.30.9 site site155
this should trick:
$ awk 'fnr==nr{a[$1]=$0;next}($1 in a){print a[$1],$2,$3}' file1 file2 server1 10.10.10.1 site site1 server2 10.10.10.2 site site2 server154 10.10.30.8 site site154 server155 10.10.30.9 site site155