Reputation: 1
Both files are sorted and duplicates removed. I want to compare field1 from file1 to field1 of file2 and output the line from file1 that is not in file2. There is no set length for field1 and that's causing me problems using uniq.
Here's an example of the data:
File1:
UUID(78-d55) NODETYPE(B) 22:42:05
UUID(78-d51) NODETYPE(B) 22:42:05
UUID(78-dca) NODETYPE(B) 22:42:37
UUID(78-494) NODETYPE(B) 22:42:37
UUID(dp@20181206003956969) NODETYPE(B) 00:39:56
File2:
UUID(78-d55) NODETYPE(B) POLNODE(/inbound/us)
UUID(78-74e) NODETYPE(B) POLNODE(/inbound/us)
UUID(78-053) NODETYPE(B) POLNODE(/inbound/us)
UUID(78-5d6) NODETYPE(B) POLNODE(/inbound/us)
UUID(78-dca) NODETYPE(B) POLNODE(/inbound/us)
UUID(78-b0b) NODETYPE(B) POLNODE(/inbound/us)
UUID(dp@20181206003956969) NODETYPE(B) POLNODE(/inbound/us)
what I want:
UUID(78-d51) NODETYPE(B) 22:42:05
UUID(78-494) NODETYPE(B) 22:42:37
Upvotes: -1
Views: 51
Reputation: 755064
Looks like a job for join
— and its -v
option:
$ join -v1 file1 file2
UUID(78-d51) NODETYPE(B) 22:42:05
UUID(78-494) NODETYPE(B) 22:42:37
$
Note that this depends on the files being sorted, as stated, and on the join columns being column 1 in each file, and on the fields being separated by blanks or tabs. Each of these can be varied by extra options if necessary.
It could also be done easily in Awk — and in Perl and Python and … other scriptable language.
Upvotes: 1