How to do uniq -d without presorting (or something similar)
问题 I am aware that I can remove duplicated lines without presorting, for example: awk '!x[$0]++' file However, my goal is to only print lines which are duplicated and only once. If it were not for the presorting problem sort | uniq -d would be perfect. BUT the order is of great importance to me. Is there a way to do this with awk, grep or something similar? I am looking for a one liner which does not require writing a script if possible. 回答1: Just check the value of x[$0] : awk 'x[$0]++ == 1'