# Count registered results based on pattern

**URL:** <https://forum.ansible.com/t/count-registered-results-based-on-pattern/18865>\
**Category:** Ansible Project\
**Created:** [July 27, 2015, 6:32pm UTC](https://forum.ansible.com/t/count-registered-results-based-on-pattern/18865 "2015-07-27T18:32:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Paine1](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Tom\_Paine1](https://forum.ansible.com/u/Tom_Paine1)\
**Post date:** [July 27, 2015, 6:32pm UTC](https://forum.ansible.com/t/count-registered-results-based-on-pattern/18865/1 "2015-07-27T18:32:52Z")

</div>

I have a collection of registered shell commands captured and would like to be able to count how many match a pattern:

`

- name: run a shell command to produce ‘a’ or ‘b’ on all boxes and collect the results  
run\_once: true  
shell: return\_a\_or\_b.sh  
register: shell\_output\_collection  
with\_items: play\_hosts  
delegate\_to: 127.0.0.1  
`

Think it’s a matter of using a filter and then a length filter after it but I can’t quite crack it:

`

- name: count how many are ‘a’  
set\_fact: count\_of\_a=“{{ shell\_output\_collection.results | map(attribute=‘stdout’) | ???match if value is ‘a’??? | list | length }}”  
`

The ‘equalto’ test is still in the jinja dev branch afaict and it’s not even certain that that will help.

How else can this be accomplished?
