How to merge the different lines of files

awkpastesort

What is the fastest command line way to merge the different lines of files? For example, I have two files:

a.txt:

foo  
bar
foobar

b.txt

foo
foobar
line
by
bar

And I would like to get the following output:

foo
bar
foobar
line
by

Is there any fast way to merge files like the example above? (The order of the lines isn't important)

Best Answer

Use awk seen if you don't want to sort the file:

$ awk '!seen[$0]++' a.txt b.txt
foo  
bar
foobar
line
by
Related Question