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

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -