0

I have a couple of arrays that contain strings that are kinda long so lets say I will use different ones just for example:

cars=("Toyota" "BMW" "Kia")

colors=("red" "blue" "green")

transmission=("manual" "manual" "automatic")

and I want to have something like this

| Cars        | Colors      | Transmission|
| ----------- | ----------- | ----------- |
| Toyota      | red         | manual      |
| BMW         | blue        | manual      |
| Kia         | green       | automatic   |

What is the smartest way to do that? Preferably without using third party tools.

s74n
  • 19
  • 3
  • It can help u: https://stackoverflow.com/a/49180405/14821847 – Andrii Nov 29 '21 at 14:12
  • Define "third party tools" – glenn jackman Nov 29 '21 at 14:14
  • I might've not been clear enough with that statement. I meant to say that preferably to use tools that are build-in linux I guess. I am going to execute a script that is on a system where installing unconfirmed software/tools is not permitted. – s74n Nov 29 '21 at 14:31

1 Answers1

2

This will get you part of the way there:

paste <(printf '%s\n' Cars "${cars[@]}") \
      <(printf '%s\n' Colors "${colors[@]}") \
      <(printf '%s\n' Transmission "${transmission[@]}") \
| column -ts $'\t'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352