a pattern check using an awk

Something like this might be sufficient for you:

$ awk 'NR > 1 && prev != $1 { sum[prev"->"$1]++ }
       { prev = $1 }
       END { for (a in sum) { print a" = "sum[a] } }
  ' input.txt
AA->CC = 1
BB->AA = 2
AA->BB = 3
BB->CC = 1
CC->AA = 2
  • Sorting is random,
  • it doesn’t print AA->CC = 1 twice 😉
  • and it doesn’t print empty relations CC->BB = 0

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top