Abdelqader Blog

Abdelqader Blog

Sort file lines in linux and delete duplicated lines

today i had an issue, pushed me to sort file lines with delete duplicated lines, then after google it i got this command

$ sort errors.log | uniq

here when i got result without duplicated and sorted

but if you wanna remove all duplicated lines you just need use this option argument (-u)

$ sort errors.log | uniq -u

and if you wanna find all duplicated lines you need use (-d) argument

$ sort errors.log | uniq -d

for more clarification you could add (-c) argument to prefix lines by the number of occurrences

$ sort errors.log | uniq -dc

*Note : if you use (-d) and (-u) arguments together you will get an empty output

Abdelqader Blog

Post a comment