Generating histogram

Hi,
I have 2 files with similar structure - reference and test that I would like to BIN both and generate the comparison.

input files structure is:

a 3
b 10
c 3
d 7
e 1
f  4
g 9
h 6

I would like the output to be (lets say both reference and test are the file above - no diff)

BIN     <2   <5   <7  <10
REF       1     4     5      7
TST       1     4     5      7

Thanks in advance

What method is BIN ?

they are pre-given constants, subject to change on rare occasion by the user.
for the example I gave they are: 2 5 7 10

something along these lines to start with:
awk -v OFS='\t' -f yan.awk refFile tstFile
where yan.awk is:

BEGIN {
  n=split("2 5 7 10", binA)
  printf("%s%s", "BIN", OFS)
  for(i=1;i<=n; i++)
    printf("%s%s", "<" binA, (i==n)?ORS:OFS)
}
function out(name,  i,empty)
{
  for(i in rangeA)
     empty++
  if (!empty) return

  printf("%s%s", name, OFS)
  for(i=1;i<=n; i++)
    printf("%d%s", rangeA, (i==n)?ORS:OFS)

}

FNR==1 {
  out(name)
  name=FILENAME
  split("",rangeA)
}
{
  for(i=1; i<=n; i++)
    if ($2<binA)
      rangeA++
}
END {
  out(name)
}
1 Like