How to remove duplicates from a file without sorting?

Duplicate lines can easily be removed with the awk command. The benefit is that no sorting is needed, so all lines remain in their original order.

Examples

awk '!x[$0]++' file.txt

Sample output

2
4
6
1
9

Recently updated at May 6, 2023

Do you like this page? Share it with others or help us make it better

Yes!

Share with friends:
Share on Twitter