How to delete identical lines while leaving one undeleted?

Hi,

I have a file as follows.

file1

Hello
Hi
His
Hi
Hi
Hungry
hi

so I want to delete identical lines while leaving one of them undeleted.

So desired output will be

Hello
Hi
His
Hungry
hi

please note that 1 'Hi' is remaining. Any ideas?

$ awk '! a[$0]++' infile
Hello
Hi
His
Hungry
hi

Hello beginner_99,

Could you please try following and let us know how it goes then.

awk '!A[$0]++'  Input_file

OR

uniq -u  Input_file

Output will be as follows in both of above commands.

Hello
Hi
His
Hungry
hi

Thanks,
R. Singh

1 Like