1

I have 3 variables, $commonName, $expiryDate and $DaysRemInUnixEpoch. Each variable has 3 lines as below output. I want to display output of all 3 variables in to 3 different columns. I tried looking for solution using printf but no luck. Can anyone please advise if they have done this in the past using printf and how? Any help will be much appreciated.

Below are 3 variables output together in one column. I want to split in to 3 columns having 3 rows in each column.

bash-4.1$ echo -e  "$commonName\n$expiryDate\n$daysRemInUnixEpoch" 
mycertificate_mycert.mycomp.net
PSIN0P551
ROOTROOTCA
Feb 6 2022 11:57:32 GMT
Jan 9 2023 18:51:25 GMT
Mar 12 2035 18:24:54 GMT
682
1020
5465
bash-4.1$

desired output I am looking for is something like below

mycertificate_mycert.mycomp.net Feb 6 2022 11:57:32 GMT 682 PSIN0P551 Jan 9 2023 18:51:25 GMT 1020 ROOTROOTCA Mar 12 2035 18:24:54 GMT 5465

0

1 Answer 1

1

With bash (Process Substitution), paste and column:

paste -d ';' <(echo "$commonName") <(echo "$expiryDate") <(echo "$daysRemInUnixEpoch") | column -s ';' -t

Output:

mycertificate_mycert.mycomp.net  Feb 6 2022 11:57:32 GMT   682
PSIN0P551                        Jan 9 2023 18:51:25 GMT   1020
ROOTROOTCA                       Mar 12 2035 18:24:54 GMT  5465

I assume that your variables do not contain ;.


see: man paste and man column

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Cyrus. paste -d does work exactly the way I want. I wasn't aware of such command. I shall look at more at man paste and man column. Thanks very much for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.