How to remove duplicates without sorting

Hello,

I can remove duplicate entries in a file by:

sort File1 | uniq > File2

but how can I remove duplicates without sorting the file?

I tried cat File1 | uniq > File2 but it doesn't work

thanks

Many ways using awk or perl. Search this site using the duplicates keyword.

Before my post I found on an older post

awk ' !x[$0]++' Infile > outFile

but it was giving syntax errors when exectued.

Then I changed awk to nawk and it worked.

thanks

You don't need a sort and uniq for removing duplicates

same can be accomplished by "-u" option

sort -u filename > new.filename

try to use nawk or /usr/xpg4/bin/awk