Create table with bash
hi all... how could I get a table that looks like this:
Variables: one = 01 to 20 every 01 two = 12 to xx every 12 (this value keeps its increment of 12 every time the "one" variable increases by one in this case until the last value of "one" is reached) three = 20 to 23 every 01 The table should look like this: one two three 01 12 20 01 12 21 01 12 22 01 12 23 01 24 20 01 24 21 01 24 22 01 24 23 01 36 20 01 36 21 01 36 22 01 36 23 02 48 20 02 48 21 02 48 22 02 48 23 02 60 20 .. .. .. 20 xx 23 I think you can see the pattern! I've been thinking over and over but no right answer came to my mind, I tried a triple for loop but could not get it to work. Any hint would be appreciated! Thanks! |
The "table" is easy; I'll assume you know how to print stuff to a shell.
For maths part, look into the `bc` command or else just variable incrementing. You'll probably want to use nested `while` loops. Hope that helps. |
thanks, do you have any idea how to declare a variable resulted from arithmetic operatio inside an array variable?
for example array=($var $var+12 $var+24 $var+36) |
You want to print this, or put it into a variable? If the former then it is three nested cycle and one printf
|
ok thanks i will try tomorrow morning and put the code here if i get stuck again at some point
|
I would add that your explanation of the fields does not follow your example data!
If we ignore column 2 for the moment, even though columns 1 and 3 start with different numbers your incremental information was the same: one = 01 to 20 every 01 three = 20 to 23 every 01 Yet your example shows: Code:
one two three So either you need to provide a better explanation or your current example needs to be altered. |
Quote:
|
Thanks for pointing out my mistake grail and keefaz, I just modified the original post, In fact the problem is that every time the variable "one" increments i want to keep the variable "two" increasing by 12 until the last value of "one" is reached
Im creating a little script, in a few minutes i will post it so you can see where I have the problem! |
If I understood correctly, this following bash script should generate the table as you requested:
Code:
#!/bin/bash |
Thanks a lot gda! it works!
|
gda's code
Code:
01 12 20 Code:
01 12 20 |
The example is still confusing, why the value 56 on column two?
column 1 is incremented by one after column 2 has incremented by 12 two times, correct? |
Think about how nested loops work. The only thing different about column 2 is that it always is incremented by 12.
|
Quote:
Anyway you are right the example table is not consistent with these requirements. So I supposed the table was wrong. Is my interpretation correct? |
Yes, but without knowing the relationship between one,two and three there are many possibilities.
Only the OP knows... |
All times are GMT -5. The time now is 04:07 PM. |