0

I tried many things but most of them just got stuck or didn't remove the duplicates properly. It doesnt matter if the output file is sorted or not

If file1.txt contains

a
b
c
d
e
c
d

If file2.txt contains

c
d
e
a
f
g
g
h

output.txt should contain

a
b
c
d
e
f
g
h

0

simply use sort -u file[12].txt >output.txt. that sorts the input while removed duplicates.

make sure your files are in Unix type newline format (LF \n) instead of Dos/Windows newline format (CRLF \r\n); if not convert them by tr -d $'\r' <filename or dos2unix filename command.

3
  • I tried that. I used sort -u first.txt second.txt third.txt >output.txt but this is what i got. The duplicates didn't get removed Apr 6 '20 at 7:11
  • @AedenThomas convert your files to Unix format with dos2unix filename (or tr -d $'\r' <filename) command then run sort .... Apr 6 '20 at 7:24
  • thanks it worked Apr 6 '20 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.