# Need help in formatting register variable

**URL:** <https://forum.ansible.com/t/need-help-in-formatting-register-variable/32840>\
**Category:** Ansible Project\
**Created:** [May 4, 2020, 11:40am UTC](https://forum.ansible.com/t/need-help-in-formatting-register-variable/32840 "2020-05-04T11:40:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [May 4, 2020, 11:40am UTC](https://forum.ansible.com/t/need-help-in-formatting-register-variable/32840/1 "2020-05-04T11:40:40Z")

</div>

I have used the below play to display the files and folders with some pattern

- name: Display backup files  
&nbsp;&nbsp;shell: "du -h {{partition}} --time | sort -rh | grep -o -P '(.\*bk|.\*bkup|.\*bak|.\*backup|.\*logs' | sort -rh | awk -F'\t' '{print $3}'|uniq|head -n 100"  
&nbsp;&nbsp;register: status

and while using this command i am getting output as below which i have stored in register variable called status

7.4G 2018-12-24 03:46 /logs/backups  
6.4G 2018-12-24 03:46 /logs/backups/config\_bkp\_11dec  
7.4G 2018-12-24 03:46 /logs/backups/config\_bkp\_18nov

The thing is i need to eliminate the entire child path lines amd need to hold the parent path /logs/backups... is there anyway to do that...

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 4, 2020, 4:12pm UTC](https://forum.ansible.com/t/need-help-in-formatting-register-variable/32840/2 "2020-05-04T16:12:06Z")

</div>

Hi

Not sure what "eliminate the entire child path lines" means - is that  
some local jargon?  
Giving actual preferred output would avoid us doing any guestimations  
and/or (mis)interpretations of said jargon.

Either way, yes you're using ansible, but just it's 'shell' module as  
a conveyor mechanism to execute a lot of piped shell commands.  
I would suggest adding a few extra.  
If any, this would avoid you dividing the text processing between the  
shell and ansible.

Dick

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 4, 2020, 5:29pm UTC](https://forum.ansible.com/t/need-help-in-formatting-register-variable/32840/3 "2020-05-04T17:29:28Z")

</div>

> Hi
> 
> Not sure what "eliminate the entire child path lines" means - is that  
> some local jargon?  
> Giving actual preferred output would avoid us doing any guestimations  
> and/or (mis)interpretations of said jargon.
> 
> Either way, yes you're using ansible, but just it's 'shell' module as  
> a conveyor mechanism to execute a lot of piped shell commands.  
> I would suggest adding a few extra.  
> If any, this would avoid you dividing the text processing between the  
> shell and ansible.
> 
> Dick

I agree, this is not related to Ansible proper. And I'm also sure that this shell command is way too complicated.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
