Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. { a[$2,NR]=$0; c[$2]++ }
  2. END {
  3. for( k in a ) {
  4.  
  5. split(k,b,SUBSEP)
  6.  
  7. t=c[b[1]] # added this bit to capture count
  8.  
  9. if( b[1] in c && t>1 ) { # added && t>1 only print if count more than 1
  10. print RS "TIMES ID" RS c[b[1]] " " b[1] RS
  11. delete c[b[1]]
  12. }
  13.  
  14. for(i=1;i<=NR;i++) if( a[b[1],i] ) {
  15. if(t>1){print a[b[1],i]} # added if(t>1) only print lines if count more than 1
  16. delete a[b[1],i]
  17. }
  18. }
  19. }
  20.  
  21. abc,2,3
  22. def,3,4
  23. ghi,2,3
  24. jkl,5,9
  25. mno,3,2
  26.  
  27. Output:
  28. TIMES ID
  29. 2 2
  30.  
  31. abc,2,3
  32. ghi,2,3
  33.  
  34. TIMES ID
  35. 2 3
  36.  
  37. def,3,4
  38. mno,3,2
  39.  
  40. END {
  41. for (k in a) {
  42. split (k,b,SUBSEP)
  43. if (c[b[1]] > 1) {
  44. if (! o[b[1]]) o[b[1]] = c[b[1]] " " b[1] RS
  45. o[b[1]] = o[b[1]] RS a[k]
  46. }
  47. delete a[k]
  48. }
  49. for (q in o) print o[q] RS
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement