Using Windows/DOS shell/batch commands, how do I take a file and only keep unique lines?

前端 未结 8 1318
刺人心
刺人心 2020-12-06 02:56

Say I have a file like:

apple
pear
lemon
lemon
pear
orange
lemon

How do I make it so that I only keep the unique lines, so I get:



        
8条回答
  •  半阙折子戏
    2020-12-06 03:02

    Use GNU sort utility:

    sort -u file.txt
    

    If you're on Windows and using Git, then sort and many more useful utilities are already here: C:\Program Files\Git\usr\bin\

    Just add this path to your %PATH% environment variable.

提交回复
热议问题