gameboy90
gameboy90

Reputation: 303

better way to get file1 and file2 union content via linux file command?

There is a file1 and another file file2, then my solution to get the union file of file1 and file2 is:

  1. step: get the intersection set file

    comm -1 -2 file1 file2 >>intersectionFile
    
  2. step: get the complement set file of file1

    comm -1 -3 file1 file2 >> file1ComplementFile
    
  3. step: get the complement set file of file2

    comm -2 -3 file1 file2 >> file2ComplementFile
    
  4. step: get the union set file equals the intersection set file PLUS file1's complement set file PLUS file2's complement set file

    cat intersectionFile file1ComplementFile file2ComplementFile >> unionFile
    

MY QUESTION IS is there a better OR easier way to get the union file of file1 and file2?

Upvotes: 0

Views: 2887

Answers (2)

John Hascall
John Hascall

Reputation: 9416

How about:

sort -u file1 file2

Upvotes: 1

bobah
bobah

Reputation: 18864

Your manipulations are identical to just comm file1 file2 >unionFile. Can you try just that?

Upvotes: 1

Related Questions