Если вы хотите сделать это только в awk
, можете попробовать следующее; если не беспокоится о порядке.
awk '{a[$0]++};END{for(i in a){if(a[i]==1){print i}}}' Input_file
Чтобы получить уникальные значения в том же порядке, в котором они встречаются во входном файле, попробуйте следующее.
awk '
!a[$0]++{
b[++count]=$0
}
{
c[$0]++
}
END{
for(i=1;i<=count;i++){
if(c[b[i]]==1){
print b[i]
}
}
}
' Input_file
Вывод будет следующим образом.
456
888
bbb
Объяснение: Добавление подробного пояснения к приведенному выше коду.
awk ' ##Starting awk program from here.
!a[$0]++{ ##Checking condition if current line is NOT occur in array a with more than 1 occurrence then do following.
b[++count]=$0 ##Creating an array b with index count whose value is increasing with 1 and its value is current line value.
}
{
c[$0]++ ##Creating an array c whose index is current line and its value is occurrence of current lines.
}
END{ ##Starting END block for this awk program here.
for(i=1;i<=count;i++){ ##Starting for loop from here.
if(c[b[i]]==1){ ##Checking condition if value of array c with index is value of array b with index i equals to 1 then do following.
print b[i] ##Printing value of array b.
}
}
}
' Input_file ##Mentioning Input_file name here.