# How do i use regex\_findall filter to display partial output of 'sh clock' command?

**URL:** <https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146>\
**Category:** Ansible Project\
**Created:** [May 10, 2021, 7:55pm UTC](https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146 "2021-05-10T19:55:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [May 10, 2021, 7:55pm UTC](https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146/1 "2021-05-10T19:55:37Z")

</div>

In below output, i want only the ‘May 11 2021’ to be displayed on screen.  
_Switch#sh clock_  
_02:42:19.622 Sng Tue May 11 2021_

Below is a sample script and used ‘regex’ filter as an example. How do i modify the script/ incorporate other any other filter such that my above objective is achieved?

- name: GATHER SHOW VERSION  
ios\_command:  
commands: “show clock”

register: show\_clock

- debug:  
msg:
- “{{ show\_clock.stdout[0] | regex\_findall('…)”

Thanks,  
Vikram

---

<div class="post-metadata">

**Author:** ![Andrew\_Cobb](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@Andrew\_Cobb](https://forum.ansible.com/u/Andrew_Cobb)\
**Post date:** [May 11, 2021, 2:13am UTC](https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146/2 "2021-05-11T02:13:28Z")

</div>

something like - “{{ show\_clock.stdout[0] | regex\_findall(‘[A-Z][a-z]{2}\s[0-9]{2}\s[0-9]{4}’)” should work although I am no expert so there may be a better way to do it.

I found [https://regexone.com/](https://regexone.com/) to be helpful to learn the basics and [https://regex101.com/](https://regex101.com/) for testing.

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [May 15, 2021, 6:12pm UTC](https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146/3 "2021-05-15T18:12:00Z")

</div>

Hi,

I suspect your script may show ewverything in ‘sh clock’ output and not the partial output i wanted. Thanks for the links, will check them.

Regards,  
Vikram

---

<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 16, 2021, 9:19am UTC](https://forum.ansible.com/t/how-do-i-use-regex-findall-filter-to-display-partial-output-of-sh-clock-command/35146/4 "2021-05-16T09:19:04Z")

</div>

You expect this based on? First check.

If you must parse dates like that, it requires more data. Is the first  
line ('Switch#sh clock') also part of the output? Let's assume so.  
And is the month abbreviated or not? From just 'May' we can't tell.  
Assuming it is, this works, in this century:

"{{ out | regex\_replace(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'(?s).\*(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{1,2})\\s+(20\\d\\d)$',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'\\2 \\3 \\4'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) }}"
