1

How can I count the unique log lines in a text file only until the first "-" and print the line with the count

org.springframework. - initialization started
org.springframework. - initialization started
pushAttemptLogger - initialization started
pushAttemptLogger - initialization started

example result

org.springframework. 2
pushAttemptLogger 2

reviewed: https://stackoverflow.com/questions/6712437/find-duplicate-lines-in-a-file-and-count-how-many-time-each-line-was-duplicated

5

cut -f1 -d'-' inputfile | sort | uniq -c

cut -f1 -d'-' will treat the file as dash-delimited and return only the first column in each line.

sort is necessary for uniq to work properly.

uniq -c shows only unique lines from the sorted input, including a count.

3
awk -F- 'NF>1 {count[$1]++}
         END {for (i in count) print i, count[i]}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.