bash - How to remove duplicates from a file and write to the same file? -


i know title not self-explanatory let me try explain here.

i have file name test.txt has duplicate lines. now, want remove duplicate lines , @ same time update test.txt new content.

test.txt

aaaa bbbb aaaa cccc 

i know can use sort -u test.txt remove duplicates update file new content how redirect it's output same file. below command doesn't work.

sort -u test.txt > test.txt 

so, why above command not working , whats correct way?

also there other way like

sort_and_update_file test.txt 

which sorts , automatically updates file without need of redirection.

this might work you:

sort -u -o test.txt test.txt 

Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -