Le Fri, Aug 01, 2025 at 12:44:14PM +0200, Félix Hauri via Bug reports for the 
GNU Bourne Again SHell a écrit :
> All this could be done by using `mapfile`!

I wrote a litte `arrayPopulate` function regarding your request:

  https://f-hauri.ch/vrac/arrayManip.sh.txt
  Usage: arrayPopulate [-O origin] [-n number] [-f field by row]

  $ arrayPopulate -f 3 T {a..c}{0..2}
  $ dumpArray T
   [0]='a0 a1 a2'
   [1]='b0 b1 b2'
   [2]='c0 c1 c2'
  $ arrayPopulate -f 3 -O 1 T {d..f}{0..2}
  $ dumpArray T
   [0]='a0 a1 a2'
   [1]='d0 d1 d2'
   [2]='e0 e1 e2'
   [3]='f0 f1 f2'
  $ arrayPopulate -f3 -O2 -n1 T {g..i}{0..2}
  $ dumpArray T
   [0]='a0 a1 a2'
   [1]='d0 d1 d2'
   [2]='g0 g1 g2'
   [3]='f0 f1 f2'
  $ arrayPopulate -f3 -O$((${#T[@]}-1)) T {a..b}{0..2}
  $ dumpArray T
   [0]='a0 a1 a2'
   [1]='d0 d1 d2'
   [2]='g0 g1 g2'
   [3]='a0 a1 a2'
   [4]='b0 b1 b2'

This could handle special characters like spaces, tabs and newlines.
I've done some tests, this seem to work fine with resonably small
amount of datas.

 $ time arrayPopulate -f 100 myvar {10000..50000}
 real    0m26.579s
 user    0m26.242s
 sys     0m0.116s
 $ echo Array myvar contain ${#myvar[@]} elements of ${#myvar[0]} characters.
 Array myvar contain 401 elements of 599 characters.

Populating a line of 40001 fields (240Kb) into an array of 401 entries
containing upto 599 characters took 26.6 secondes on my host:
   Core i5-4570 @3.20GHz, with 32Go ram.


-- 
 Félix Hauri  -  <fe...@f-hauri.ch>  -  http://www.f-hauri.ch

  • Improvement fo... Toni Kauppi
    • Re: Impro... Félix Hauri via Bug reports for the GNU Bourne Again SHell
      • Re: I... Félix Hauri via Bug reports for the GNU Bourne Again SHell

Reply via email to