# Copy lines from a file

**URL:** <https://forum.ansible.com/t/copy-lines-from-a-file/28579>\
**Category:** Ansible Project\
**Created:** [September 15, 2018, 9:30am UTC](https://forum.ansible.com/t/copy-lines-from-a-file/28579 "2018-09-15T09:30:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bilal\_ahmed](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@Bilal\_ahmed](https://forum.ansible.com/u/Bilal_ahmed)\
**Post date:** [September 15, 2018, 9:30am UTC](https://forum.ansible.com/t/copy-lines-from-a-file/28579/1 "2018-09-15T09:30:31Z")

</div>

Hi guys,

I want to copy a specific line (say last one) from a file (any log file) and email it using Ansible playbook. Which module can I use for this?  
Thanks in advance.

BR,  
Bilal AHMED

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [September 15, 2018, 3:40pm UTC](https://forum.ansible.com/t/copy-lines-from-a-file/28579/2 "2018-09-15T15:40:50Z")

</div>

I would use two tasks; one using the shell module to run the remote command of your choice (tail, grep, whatever) and register the output to a variable, then a second task using the mail module to send it to recipients.

---

<div class="post-metadata">

**Author:** ![Bilal\_ahmed](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@Bilal\_ahmed](https://forum.ansible.com/u/Bilal_ahmed)\
**Post date:** [September 15, 2018, 4:10pm UTC](https://forum.ansible.com/t/copy-lines-from-a-file/28579/3 "2018-09-15T16:10:50Z")

</div>

Thanks a lot dear.. I didn't knew about Shell module and had done the  
task before your reply using a bash script. But its more simple with  
Shell module which you introduced to me. Thanks again.
