Count occurrences in awk

Hello,
I have an output from GDB with many entries that looks like this

0x00007ffff7dece94	39	in dl-fini.c
0x00007ffff7dece97	39	in dl-fini.c
0x00007ffff7ab356c	50	in exit.c
0x00007ffff7aed9db in _IO_cleanup () at genops.c:1022
115	in dl-fini.c
0x00007ffff7decf7b in _dl_sort_fini (l=0x0, maps=0x7fffffffeab0, nmaps=4, 
    used=0x4 <Address 0x4 out of bounds>, ns=0) at dl-fini.c:115
0x00007ffff7ab3570	50	in exit.c
74	in exit.c

How can I count how many times "in exit.c", "in dl-fini.c" and "in genops.c" is in the file?
It shouldn't count "at+...", only "in+...".

The output has to be

3 in exit.c
2 dl-fini.c

Why not grep -c "in exit.c" inputfile and the likes?

Because it'spart of a bigger awk script, and I need it in arrays.
I also want a nice output file.

Try this script:

awk '
BEGIN{A[1]="in exit.c"; A[2]="dl-fini.c"; A[3]="in genops.c"}

{for(i in A)if($0~A)B++}

END{for(i in A){print B"\t"A}}' gdb_output
1 Like

Thanks, that works, but only for these 3.
After the "in", it can be anything...
I now have:

/in /{
count[$NF]++
}

END{
for(j in count)
print j "("count[j]")"
}

It works, but as you can see, it's not always the last field.
It's the field after "in". How can I define the arrays?
Here is a part of the source file:

0x00007ffff7ded32e	287	in dl-fini.c
0x00007ffff7ded32f in _dl_fini () at dl-fini.c:287
287	in dl-fini.c
0x00007ffff7ab3612 in __run_exit_handlers (status=15, listp=0x7ffff7dd94a8, 
    run_list_atexit=true) at exit.c:78
	in exit.c
78	in exit.c
0x00007ffff7ab3545	78	in exit.c
0x00007ffff7ab3548	78	in exit.c
46	in exit.c
78	in exit.c
46	in exit.c
83	in exit.c
84	in exit.c
83	in exit.c
84	in exit.c
90	in exit.c
0x00007ffff7ab3596	90	in exit.c
91	in exit.c
0x00007ffff7ab359f	91	in exit.c
0x00007ffff7ab35a6	91	in exit.c
0x00007ffff7ab35a9	91	in exit.c
0x00007ffff7ab35ab	91	in exit.c
_IO_cleanup () at genops.c:1007
	in genops.c

You can add more in something in the BEGIN{} block code. Sorry, I can't help you much more =/

Here you can find the source file:
GNU gdb (GDB) 7.0.1-debian Copyright (C) 2009 Free Software Foundation, Inc. L - Pastebin.com

I want the output file like this

   -               1 #include <stdio.h>
    -               2 
    -               3 int main(void)
    -               4 {
    1    0.14%      5   volatile int m=7;
    3    0.43%      6   m+=8;
    1    0.14%      7   return m;
    2    0.29%      8 } //7 1.00%
Other functions:
  419   59.94%  dl-fini.c
  152   21.75%  genops.c
   57    8.15%  exit.c
   18    2.58%  __do_global_dtors_aux
    7    1.00%  ../sysdeps/unix/sysv/linux/_exit.c
    7    1.00%  _IO_flush_all_lockp
    7    1.00%  _IO_cleanup
    7    1.00%  _dl_sort_fini
    5    0.72%  soinit.c
    4    0.57%  _fini
    2    0.29%  __run_exit_handlers
    2    0.29%  rtld.c
    2    0.29%  _dl_fini
    1    0.14%  main
    1    0.14%  libc-start.c
    1    0.14%  __libc_fini