Re: [ansible-project] split for data manitpulation

2023-10-15 Thread Veera
Hi  Vladimir ,

I got it by using the  join  -  s1_34: "{{ [[1], [3, 4]]| map('map', 
'extract', arr)| join(',')}


On Sunday, October 15, 2023 at 1:08:39 AM UTC+5:30 Vladimir Botka wrote:

> On Sat, 14 Oct 2023 10:32:51 -0700 (PDT)
> Veera  wrote:
>
> > Is there a way to combine the 2 positional values ...
> > to print like below
> > - two
> > - four five
>
> Split the string and trim the items
>
> arr: "{{ myline|split(',')|map('trim') }}"
>
> gives
>
> arr:
> - This line is a test
> - two
> - three
> - four
> - five
> - '6'
> - seven
>
> A list of lists the structure that describes what you want
>
> s1_34: "{{ [[1], [3, 4]]|
> map('map', 'extract', arr)|
> map('join', ' ') }}"
>
> gives
>
> s1_34:
> - two
> - four five
>
> You can substitute *arr* in *s1_34* if you want a 'one-liner'.
>
>
> -- 
> Vladimir Botka
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/15ad36b7-c542-4cc1-975e-d37bfd3b13f0n%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-10-14 Thread Vladimir Botka
On Sat, 14 Oct 2023 10:32:51 -0700 (PDT)
Veera  wrote:

> Is there a way to combine the 2 positional  values ...
> to print  like below
>   - two
>   - four five

Split the string and trim the items

  arr: "{{ myline|split(',')|map('trim') }}"

gives

  arr:
  - This line is a test
  - two
  - three
  - four
  - five
  - '6'
  - seven

A list of lists the structure that describes what you want

  s1_34: "{{ [[1], [3, 4]]|
   map('map', 'extract', arr)|
   map('join', ' ') }}"

gives

  s1_34:
  - two
  - four five

You can substitute *arr* in *s1_34* if you want a 'one-liner'.


-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20231014213815.4d34a4de%40gmail.com.


pgpayI00Z88D5.pgp
Description: OpenPGP digital signature


Re: [ansible-project] split for data manitpulation

2023-10-14 Thread Veera
Hi Todd,

Is there a way to combine the 2 positional  values .

 "{{ [2, 4, 5] | map('extract', myline.split(',')) }}" 
as 
 "{{ [2, 4 5] | map('extract', myline.split(',')) }}" 
  to print  like below
  - two
 -  four five

I tried to combine .. but missing a bit
 "{{ [2, combine [4 5] | map('extract', myline.split(',')) }}" or  printing 
"two" as  a item and  "{{ [4 5] | map('extract', myline.split(',')) 
|combine }}"

or a different filter instead of combine can help?


On Tuesday, August 29, 2023 at 5:24:04 PM UTC+5:30 Todd Lewis wrote:

> You have 6 delimiters, so only 7 fields. Your maximum index therefore is 6.
>
> Setting that issue aside, you can use map(), like so:
>
> "{{ [2, 4, 5] | map('extract', myline.split(',')) }}"
>
> Cheers,
> --
> Todd
>
>
> On 8/29/23 3:40 AM, Veera wrote:
>
> Hi, 
>
> I have this playbook to print the columns  5 and 6 using the debug.
>
> ---
> - name: playbook to print columns
>   hosts: localhost
>   gather_facts: no
>   vars:
> myline: This line is a test, two, three, four, five, 6, seven 
>   tasks:
> - name: play to  print
>   debug:
> msg: 
>   - "{{ myline.split(',')[5] }}"
>   - "{{ myline.split(',')[6] }}"
>
> It prints the details , But is there a way to print the columns  4,7 and 
> 11 with a single split option. (instead of listing under msg: )
>
>  - name: play to  print
>   debug:
> msg:  "{{ myline.split(',')[4][7][11] }}"
>
> Do split accepts only one square bracket[] parameter? 
>  
>   
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com
>  
> 
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/062d69ec-9f66-4595-ad31-693d7961ef23n%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-08-29 Thread Veera
Thanks  Todd. 
 I  got the desired output  and it answers the other thread also .
https://groups.google.com/g/ansible-project/c/ZqZuw3do-5g/m/hMlDvLceAQAJ  
 (Now I understand it is a string.. )





On Tuesday, August 29, 2023 at 5:24:04 PM UTC+5:30 Todd Lewis wrote:

> You have 6 delimiters, so only 7 fields. Your maximum index therefore is 6.
>
> Setting that issue aside, you can use map(), like so:
>
> "{{ [2, 4, 5] | map('extract', myline.split(',')) }}"
>
> Cheers,
> --
> Todd
>
>
> On 8/29/23 3:40 AM, Veera wrote:
>
> Hi, 
>
> I have this playbook to print the columns  5 and 6 using the debug.
>
> ---
> - name: playbook to print columns
>   hosts: localhost
>   gather_facts: no
>   vars:
> myline: This line is a test, two, three, four, five, 6, seven 
>   tasks:
> - name: play to  print
>   debug:
> msg: 
>   - "{{ myline.split(',')[5] }}"
>   - "{{ myline.split(',')[6] }}"
>
> It prints the details , But is there a way to print the columns  4,7 and 
> 11 with a single split option. (instead of listing under msg: )
>
>  - name: play to  print
>   debug:
> msg:  "{{ myline.split(',')[4][7][11] }}"
>
> Do split accepts only one square bracket[] parameter? 
>  
>   
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com
>  
> 
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0191ec3a-4cf5-4d63-9fcf-b39761c012f0n%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-08-29 Thread Todd Lewis

You have 6 delimiters, so only 7 fields. Your maximum index therefore is 6.

Setting that issue aside, you can use map(), like so:

"{{ [2, 4, 5] | map('extract', myline.split(',')) }}"

Cheers,
--
Todd

On 8/29/23 3:40 AM, Veera wrote:

Hi,

I have this playbook to print the columns  5 and 6 using the debug.

---
- name: playbook to print columns
  hosts: localhost
  gather_facts: no
  vars:
    myline: This line is a test, two, three, four, five, 6, seven
  tasks:
    - name: play to  print
      debug:
        msg:
          - "{{ myline.split(',')[5] }}"
          - "{{ myline.split(',')[6] }}"

It prints the details , But is there a way to print the columns  4,7 
and 11 with a single split option. (instead of listing under msg: )


 - name: play to  print
      debug:
        msg:  "{{ myline.split(',')[4][7][11] }}"

Do split accepts only one square bracket[] parameter?


--
You received this message because you are subscribed to the Google 
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/488250f7-8ddb-056d-54a1-230223265d37%40gmail.com.


Re: [ansible-project] split for data manitpulation

2023-08-29 Thread dulhaver via Ansible Project
> Do split accepts only one square bracket[] parameter?
 
the python aquivalent (something similar to this should be happening in the 
backgound) would be:
 
   >>> myline = 'This line is a test, two, three, four, five, 6, seven'
   >>> print(myline.split(',')[4], myline.split(',')[5], myline.split(',')[6])
   five 6 seven
 
as you do not have an index 11 your concrete example makes no big sense in that 
regards.
 
I neither found the correct ansible syntax to translate that mentioned python 
logic into a TASK example like yours though.
maybe someone else here can help out with that
 
 

> On 08/29/2023 9:40 AM CEST Veera  wrote:
>  
>  
> Hi,
>  
> I have this playbook to print the columns  5 and 6 using the debug.
>  
> ---
> - name: playbook to print columns
>   hosts: localhost
>   gather_facts: no
>   vars:
> myline: This line is a test, two, three, four, five, 6, seven
>   tasks:
> - name: play to  print
>   debug:
> msg:
>   - "{{ myline.split(',')[5] }}"
>   - "{{ myline.split(',')[6] }}"
>  
> It prints the details , But is there a way to print the columns  4,7 and 11 
> with a single split option. (instead of listing under msg: )
>  
>  - name: play to  print
>   debug:
> msg:  "{{ myline.split(',')[4][7][11] }}"
>  
> Do split accepts only one square bracket[] parameter? 
>  
>   
>  
>  
> 
>  
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-project+unsubscr...@googlegroups.com 
> mailto:ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com
>  
> https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com?utm_medium=email_source=footer.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1357095435.216963.1693300916372%40office.mailbox.org.


[ansible-project] split for data manitpulation

2023-08-29 Thread Veera
Hi,

I have this playbook to print the columns  5 and 6 using the debug.

---
- name: playbook to print columns
  hosts: localhost
  gather_facts: no
  vars:
myline: This line is a test, two, three, four, five, 6, seven 
  tasks:
- name: play to  print
  debug:
msg: 
  - "{{ myline.split(',')[5] }}"
  - "{{ myline.split(',')[6] }}"

It prints the details , But is there a way to print the columns  4,7 and 11 
with a single split option. (instead of listing under msg: )

 - name: play to  print
  debug:
msg:  "{{ myline.split(',')[4][7][11] }}"

Do split accepts only one square bracket[] parameter? 
 
  


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com.