April 24, 2026

Remove duplicated rows of a csv or tsv file

Print duplicates:

$ sort file.csv | uniq -d

Create a new file without duplicates:

$ awk '!seen[$0]++' file.csv > no_dup.csv

Where I understand $0 is the whole line/row of arguments; so the whole line/row would have to be identical for it to be removed. In some of the file I have I want to remove the line if the email address of the entry/line/row is a duplicated. So, I substituted $0 for $5, that is the fifth field, in awk terminology (the fifth column):

$ awk '!seen[$5]++' file.csv > no_dup.csv

And this worked for me, but I can find an explanation that corroborate this syntax.

More commands at: https://yctct.com/data-cleaning-101


personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki data

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2025 by yctct is licensed under CC BY-SA 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88