I have a problem, there are a series of commands that generate me data that are stored in the variables $nombreioc, $valorioc and $recursoioc, these are printed in the following table:
+------------+-----------+---------------------+
| Type | Value | Adicional Resources |
+------------+-----------+---------------------+
| $nombreioc | $valorioc | $recursoioc |
+------------+-----------+---------------------+
The problem is that the variables have different numbers of characters and the whole table must be adapted to the length of the variable at that moment.
All that I want to do in shellscript, linux
I have tried to use \t with echo, but it does not work
Note the missing
|at the end of each line in thecolumnoutput above, here's the fix for that:Note the extra blank I added after the final
|on each echoed line above to forcecolumnto add the trailing|, otherwise it wouldn't print that nor, more importantly, the padding blanks after the final data value before it on each line.If you don't have
columnyou could always do it all in awk, e.g. given this input:here's a solution using any awk reading the input file twice (so will work for input from any size of file but won't work for input coming from a pipe):
or reading the input file once and storing all of the input in memory (so it will work with input from a file or a pipe as long as that input isn't so huge that it can't be store in memory):