Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { a[$2,NR]=$0; c[$2]++ }
- END {
- for( k in a ) {
- split(k,b,SUBSEP)
- t=c[b[1]] # added this bit to capture count
- if( b[1] in c && t>1 ) { # added && t>1 only print if count more than 1
- print RS "TIMES ID" RS c[b[1]] " " b[1] RS
- delete c[b[1]]
- }
- for(i=1;i<=NR;i++) if( a[b[1],i] ) {
- if(t>1){print a[b[1],i]} # added if(t>1) only print lines if count more than 1
- delete a[b[1],i]
- }
- }
- }
- abc,2,3
- def,3,4
- ghi,2,3
- jkl,5,9
- mno,3,2
- Output:
- TIMES ID
- 2 2
- abc,2,3
- ghi,2,3
- TIMES ID
- 2 3
- def,3,4
- mno,3,2
- END {
- for (k in a) {
- split (k,b,SUBSEP)
- if (c[b[1]] > 1) {
- if (! o[b[1]]) o[b[1]] = c[b[1]] " " b[1] RS
- o[b[1]] = o[b[1]] RS a[k]
- }
- delete a[k]
- }
- for (q in o) print o[q] RS
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement