I have a text file with example (two columns separated with a :)
if the first columns first row is repeated again then dont consider it and give the output
11:22
33:44
55:66
55:77
my desired output should be
11:22
33:44
2 Answers
sort file | uniq --unique --check-chars=2I'm making two assumptions:
- it's okay to change the row order (sort)
- the first column will always be two characters wide
For excluding the lines that have repetition of first column only:
sort file | uniq -u -w 1For excluding the lines that have repetition of first field when delimited by colon:
cut -d: -f1 file | sort | uniq -uIn the two cases, we need to sort the file before piping the output to uniq (as uniq works on adjacent matching lines). Then do uniq with some options.
From uniq man page:
-u: only print unique lines
-w N: compare no more than N characters in lines 2