Demo file stuff.txt
contains:
one
two
three
one
two
four
five
Remove duplicate lines from a file assuming you don't mind that lines are sorted
$ sort -u stuff.txt
five
four
one
three
two
Explanation: the u flag sent to sort says sort the lines of the file and force unique.
Remove duplicate lines from a file, preserve original ordering, keep the first:
$ cat -n stuff.txt | sort -uk2 | sort -nk1 | cut -f2-
one
two
three
four
five
Explanation: The n flag passed to cat appends line numbers to left of every line, plus space, then the first sort says sort by unique and but only after the first word, the second sort command says use the line numbers we stored in step 1 to resort by the original ordering, finally cut off the first word.
Remove duplicate lines from a file, preserve order, keep last.
tac stuff.txt > stuff2.txt; cat -n stuff2.txt | sort -uk2 | sort -nk1 | cut -f2- > stuff3.txt; tac stuff3.txt > stuff4.txt; cat stuff4.txt
three
one
two
four
five
Explanation: Same as before, but tac reverse the file, achieving the desired result.
sort file|uniq
will do what you want.