# register output from shell command, match line to supplied value and return value of different column

**URL:** <https://forum.ansible.com/t/register-output-from-shell-command-match-line-to-supplied-value-and-return-value-of-different-column/29179>\
**Category:** Ansible Project\
**Created:** [December 3, 2018, 2:03pm UTC](https://forum.ansible.com/t/register-output-from-shell-command-match-line-to-supplied-value-and-return-value-of-different-column/29179 "2018-12-03T14:03:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ansible\_Madness](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Ansible\_Madness](https://forum.ansible.com/u/Ansible_Madness)\
**Post date:** [December 3, 2018, 2:03pm UTC](https://forum.ansible.com/t/register-output-from-shell-command-match-line-to-supplied-value-and-return-value-of-different-column/29179/1 "2018-12-03T14:03:54Z")

</div>

merely looking for some suggestions how to perform the following actions in ansible

1. run a shell command (ok this one is easy), it will return a list of values in the format of:

A B C D  
D E F G

1. now i want to match a line with a value and return the value of a DIFFERENT column… so using the above, i want to match F but return the value of column 1 (in the example this would be “D”) as a variable that i can use further in the playbook.  
(matching the search value is easy to get a true or false however i am perplexed how to do this the ansible way)

In pure linux i could hack this with a grep of “F” and awk out the column i want, but trying to not do everything with the shell module if i dont need to.

Any suggestions welcome.

Thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 3, 2018, 2:45pm UTC](https://forum.ansible.com/t/register-output-from-shell-command-match-line-to-supplied-value-and-return-value-of-different-column/29179/2 "2018-12-03T14:45:38Z")

</div>

Parsing string/text in Ansible is not trivial as you would need a lot more code to do it.  
Since you already running shell piping it through awk '{if ($3 == "F") print $1}' is a lot easier.
