TransWikia.com

Map bash table output to array

Stack Overflow Asked by Jeroen Smink on December 12, 2020

How can i map the value’s I got from the column name into an array that i can later use in my bash script?

+------------------------------+----------+-----------+---------+
| name                         | status   | update    | version |
+------------------------------+----------+-----------+---------+
| enable-jquery-migrate-helper | inactive | none      | 1.0.1   |
| gravityforms                 | inactive | none      | 2.4.17  |
| gutenberg                    | inactive | none      | 8.8.0   |
| redirection                  | inactive | none      | 4.8     |
| regenerate-thumbnails        | inactive | none      | 3.1.3   |
| safe-svg                     | inactive | none      | 1.9.9   |
| weglot                       | inactive | none      | 3.1.9   |
| wordpress-seo                | inactive | available | 14.8    |
+------------------------------+----------+-----------+---------+

I already tried the following, but this would only save the name of the headers in the table:

IFS=$'n' read -r -d '' -a my_array < <( wp plugin list  --status=inactive --skip-plugins  && printf '' )

echo $my_array

 name status update version

After I have retrieved the value’s I want to loop over them to add them to an array

One Answer

Better use the CSV output format rather than the default table format if your intent is mapping the result with a shell or awk script:

wp plugin list --status=inactive --skip-plugins --format=csv

which would output this:

name,status,update,version
enable-jquery-migrate-helper,inactive,none,1.0.1
gravityforms,inactive,none,2.4.17 
gutenberg,inactive,none,8.8.0
redirection,inactive,none,4.8
regenerate-thumbnails,inactive none,3.1.3
safe-svg,inactive,none,1.9.9
weglot,inactive,none,3.1.9
wordpress-seo,inactive,available,14.8

Correct answer by Léa Gris on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP