Skip to main content
2 of 2
added 182 characters in body
Romeo Ninov
  • 19.5k
  • 5
  • 35
  • 48

Based on other answer you can use sort command but you can explicitly mention output file and do the sort in place (w/o intermediate file)

sort -u -o new.txt old.txt new.txt 

One of possible awk ways:

awk -i inplace '{z[$0]=1} END{for( i in z) print i}' new.txt old.txt 

Be warned that this can "eat" a lot of memory if one or both input files are long. inplace will keep the output in new.txt

Romeo Ninov
  • 19.5k
  • 5
  • 35
  • 48