Link to home
Create AccountLog in
Avatar of MatthewF
MatthewFFlag for Afghanistan

asked on

Compare first 3 fields between two files

I need to compare just the first three fields between 2 different files.

the first file have lines with 3 fields
servername1 WINDOWS daily

The second file have lines with 5 fields
servername1 WINDOWS daily 24 remotehost
servername2 WINDOWS daily 24 remotehost

I want to print to a third file where the fiirst 3 field exist in the seonds file but do not exist in the first file, so in this instance the third file would contain the second line from the second file

servername2 WINDOWS daily 24 remotehost




ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
perl -ane 'print unless $s{"@F[0..2]"}++ or @ARGV' first second > third
As always, ozo is king of the one-liners.

I'm an expert at perl but often learn something new (or at least make me think) from ozo's one-liners.