Count and print the number of occurences

I have some files as 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 is 654. The value of ALM is 656. In the same way, 4th column represents the values of first column. 5th column represents the values of second column.

I tried the following program to count the occurrences of each number in the fourth and fifth column.

 for i in folder1/*.pdb;
do
awk '
BEGIN {
    path=sprintf("%s", "/home/arch/Desktop/folder2/")
}
!s[1":"$4":"$5]++{sU[$4]++;tot++} 
!s[2":"$4":"$5]++{sU[$5]++;tot++} 
END { 
    sub(/.*\//,"",FILENAME)
    for (x in sU) 
        print x, sU[x], sU[$1] > path FILENAME;       
}'  $i;
 done

The above program prints as follows

660 1 
654 1 
655 1 
656 2 
657 1 
658 2 

Desired Output:-

 660 LEG 1
 654 GLL 1
 655 SEM 1
 656 ALM 2
 657 LYG 1
 658 LEG 2 

your suggestions would be appreciated!!

awk '
        {
                F[$4" "$1]++
                F[$5" "$2]++
        }
        END {
                for ( k in F )
                        print k, F[k]
        }
' file

Hi yoda,

Thanks for your code. I need only unique numbers. For eg: using your program, The number 658 prints 5. I need to print it as 2.

I don't get 5 for 658 if I run this code on your input data. Here is what I get:

658 ARN 3
655 SEM 2
660 LEG 2
656 ALK 1
656 ALM 3
654 GLL 1
658 LEG 2
657 LYG 2

Because there are 3 occurrence of 658 ARN & 2 occurrences of 658 LEG.

So if this is not what you want, then post the output that you need.

Hi yoda

I have posted my desired output. I need only unique occurrences.
In case of SEM, your output is 2. I need it as 1. I don't need duplicate occurrences.

SEM  LYG  655-657  655  657  
SEM  LYG  655-657  655  657 
655 SEM  1
657 LYG  1

insert data in a file and run the check as below

grep -c "654" <file_name>

It gives desired result.You may like to use it in a for loop for more efficient result