Reputation: 467
I'm trying to know which are the lines that are repeated X times in a text file, and I'm using awk
but I see that awk
in my command, not work with lines that begin with the same characters or words. That is, does not recognize the full line individually.
Using this command I try to get the lines that are repeated 3 times:
awk '++A[$1]==3' ./textfile > ./log
Upvotes: 1
Views: 156
Reputation: 352
This returns lines repeated 3 times but adds a space at the beginning of each 3x-repeated line:
sort ./textfile | uniq -c | awk '$1 == 3 {$1 = ""; print}' > ./log
Upvotes: 0
Reputation: 5298
This is what you need hopefully:
awk '{a[$0]++}END{for(i in a){if(a[i]==3)print i}}' File
Increment array a
with the line($0
) as index for each line. In the end, for each index ($0
), check if the count(a[i]
which is the original a[$0]
) equals 3
. If so, print the line (i
which is the original $0
/ line). Hope it's clear.
Upvotes: 3