extracting unique values between 2 sets/files

前端 未结 8 1224
粉色の甜心
粉色の甜心 2020-11-29 19:44

Working in linux/shell env, how can I accomplish the following:

text file 1 contains:

1
2
3
4
5

text file 2 contains:



        
8条回答
  •  旧巷少年郎
    2020-11-29 20:25

    How about:

    diff file_1 file_2 | grep '^>' | cut -c 3-
    

    This would print the entries in file_2 which are not in file_1. For the opposite result one just has to replace '>' with '<'. 'cut' removes the first two characters added by 'diff', that are not part of the original content.

    The files don't even need to be sorted.

提交回复
热议问题