# Filter specific string from file content and it needs to be looped into mail module

**URL:** <https://forum.ansible.com/t/filter-specific-string-from-file-content-and-it-needs-to-be-looped-into-mail-module/29103>\
**Category:** Ansible Project\
**Created:** [November 23, 2018, 12:27pm UTC](https://forum.ansible.com/t/filter-specific-string-from-file-content-and-it-needs-to-be-looped-into-mail-module/29103 "2018-11-23T12:27:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pandu\_jh](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@Pandu\_jh](https://forum.ansible.com/u/Pandu_jh)\
**Post date:** [November 23, 2018, 12:27pm UTC](https://forum.ansible.com/t/filter-specific-string-from-file-content-and-it-needs-to-be-looped-into-mail-module/29103/1 "2018-11-23T12:27:10Z")

</div>

I have multiple files in a path and it contains mail id of the users.  
I need to loop the file content using with\_items and filter users ID from the file content.  
That ID’s should be passed into mail module, mail needs to be sent to those user ID’s.

Please help me filter only ID form the file content and it needs to be looped into mail module.

cat /test/user1

Name: Anton  
ID: [anton.s@xxx.com](mailto:anton.s@xxx.com)

cat /test/user2  
Name: Jeniffer  
ID: [jennifer.m@xxx.com](mailto:jennifer.m@xxx.com)

- shell: cat {{ item }} | egrep -v ‘provided|valid’  
register: file\_content  
with\_items:

- /test/user1

- /test/user2

- name: Send mail notification to the user  
mail:  
host: [mailrelay.xxx.com](http://mailrelay.xxx.com)  
port: 25  
body: “{{ lookup(‘file’, ‘{{ req\_path }}/{{ req }}’) + lookup(‘file’, ‘{{ mail\_sign }}’) }}”  
charset: utf8

run\_once: true
