# Remove last characters(.zip) from listed output llines in windows ansible

**URL:** <https://forum.ansible.com/t/remove-last-characters-zip-from-listed-output-llines-in-windows-ansible/31577>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 31, 2019, 9:52am UTC](https://forum.ansible.com/t/remove-last-characters-zip-from-listed-output-llines-in-windows-ansible/31577 "2019-10-31T09:52:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [October 31, 2019, 9:52am UTC](https://forum.ansible.com/t/remove-last-characters-zip-from-listed-output-llines-in-windows-ansible/31577/1 "2019-10-31T09:52:18Z")

</div>

Hi all,

I wanted to remove the .zip from output line in the ansible from below;

“result.stdout\_lines”: [  
“Database\_0.0.100.zip”,  
“EMC\_ECS-package\_0.0.100.zip”,  
“hotfix-DDMInfra.zip”,  
“hotfix-IIS.zip”,  
“hotfix-QCIM1H126382-v3.zip”,  
“MMiS\_Offering\_0.0.108.zip”,  
“Network\_v\_0.0.100.zip”,  
“NormalizationRules\_100.zip”,  
“UDAgentManagement\_10.33.0.zip”,  
“UDI\_Data\_Model\_0.0.104.zip”,  
“UDI\_Discovery\_Administration\_100.zip”,  
“UDI\_Discovery\_Base\_Enrichment\_0.0.105.zip”,  
“UDI\_TenantAssociationRules\_100.zip”,  
“WebService\_0.0.103.zip”,  
“XCDE\_Outbound\_Adapter\_0.0.101.zip”

for remove .zip I added task as below:

- debug: msg=“{{ result.stdout\_lines[0:-2] }}”  
with\_items:
- “{{ result.stdout\_lines }}”

but output is remove the “XCDE\_Outbound\_Adapter\_0.0.101.zip” and “WebService\_0.0.103.zip”, not .zip

Could you please let me know how to remove the .zip from each line?  
the expected output should be;  
" Database\_0.0.100",  
“EMC\_ECS-package\_0.0.100”,  
“hotfix-DDMInfra”,  
“hotfix-IIS.zip”,  
“hotfix-QCIM1H126382-v3”, …etc…

Best regards,  
Venkat

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 31, 2019, 11:02am UTC](https://forum.ansible.com/t/remove-last-characters-zip-from-listed-output-llines-in-windows-ansible/31577/2 "2019-10-31T11:02:28Z")

</div>

This debug probably fix the problem

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ item[:-4] }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ result.stdout\_lines }}"

, but to get the modified list use this

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_list: "{{ result.stdout\_lines|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map('regex\_replace', regex, replace)|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regex: '(.\*?)(\.zip)?'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replace: '\1'

Cheers,

&nbsp;&nbsp;-vlado
