次のように、4番目のフィールドがまだ配列に含まれていないかどうかをテストする必要があります。
BEGIN {
print "Begin Processing of various Records"
}
$3 ~ /add/ && $5 ~ /true/ && !a[$4]++ {
i++
print
}
END {
print "Process Complete. Records found:", i
}
結果:
Begin Processing of various Records
INFO #my-service# #add# id=67986324423 isTrial=true
INFO #my-service# #add# id=43634636365 isTrial=true
Process Complete. Records found: 2
ここにあなたが興味を持つかもしれないいくつかの情報があります。HTH。
以下のコメントのように、これを行うこともできます:
BEGIN {
print "Begin Processing of various Records"
}
$3 ~ /add/ && $5 ~ /true/ && !a[$4] {
a[$4]++
print
}
END {
print "Process Complete. Records found:", length(a)
}
これは次のものとは大きく異なることに注意してください。
BEGIN {
print "Begin Processing of various Records"
}
$3 ~ /add/ && $5 ~ /true/ && !a[$4] {
# See the line below. I may not have made it clear in the comments that
# you can indeed add things to an array without assigning the key a
# value. However, in this case, this line of code will fail because our
# test above (!a[$4]) is testing for an absence of value associated
# with that key. And the line below is never assigning a value to the key!
# So it just won't work.
a[$4]
# Technically, you don't need to increment the value of the key, this would
# also work, if you uncomment the line:
# a[$1]=1
print
}
END {
print "Process Complete. Records found:", length(a)
}