awk - count and print the number of occurences -


i have files shown below

gll  alm  654-656  654  656  sem  lyg  655-657  655  657 sem  lyg  655-657  655  657  alm  leg  656-658  656  658  alm  leg  656-658  656  658   alm  leg  656-658  656  658   leg  leg  658-660  658  660  leg  leg  658-660  658  660 

the value of gll 654. value of alm 656. in same way, 4th column represents values of first column. 5th column represents values of second column.i count unique occurrences of each number in fourth , fifth column.

desired output

654 gll 1 655 sem 1 656 alm 2 657 lyg 1 658 leg 2 660 leg 1 

if understand question right, script give output:

awk '{d[$4]=$1;d[$5]=$2;p[$4];l[$5]} end{     for(k in p){         if (k in l){             delete l[k]             print k,d[k],"2"         }else         print k,d[k],"1"     }     (k in l)         print k, d[k],1 } ' file 

with input data, output of above script:

654 gll 1 655 sem 1 656 alm 2 658 leg 2 657 lyg 1 660 leg 1 

so not 100% same expected output (the order), if pipe sort -n, gonna give same thing. sorting part done within awk too. bit lazy... :)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -