Hello everybody.
My operating system is Fedora30, shell - bash
I faced combining lists. I will be glad for help regarding strings, arrays and so on.
The bottom line is as follows. It is necessary to combine each element from the first list with elements from the second.
if the second is longer than the first then need to discard excess.
If the second is less than the first, add elements in a circular.
That is, to pair them in this way
first list:
a b c d i f gg
second list:
1 2 13
desire:
a1 b2 c13 d1 i2 f13 gg1
What conclusion does not matter. May be so:
a 1
b 2
c 13
...
With any separator:
a1,b2,c13,...,gg1
Since the parameters were passed to the function and it was possible to calculate the length of the first list in advance,
the solution was to make the second list redundant and cut off the necessary from the head
arr=(a b c d i f gg) #arr=($1)
paste <(fmt -1 <<<"a b c d i f gg") <(printf %.s'1 2 13 ' $(seq ${#arr[@]}) | fmt -1 | head -${#arr[@]})
Or a more accurate solution.
paste <(fmt -1 <<<"a b c d i f gg") <(yes $'1\n2\n13' | head -${#arr[@]})
Moreover, it is not difficult to convert a variable into functions yes "${2// /$'\n'}"
On the fly from the command line, it will be harder to do!
It seems to me that the solution should be very simple and I'm missing something
I am also interested in decisions regarding single-character lists. I would be grateful for all the solutions.
Thanks everyone