How to merge two arrays in a zipper like fashion in Bash?

后端 未结 5 1832
野趣味
野趣味 2020-11-29 13:23

I am trying to merge two arrays into one in a zipper like fashion. I have difficulty to make that happen.

array1=(one three five seven)
array2=(two four six          


        
5条回答
  •  -上瘾入骨i
    2020-11-29 13:42

    You can easily read the files, create an array with their content, check who is the bigger one and make the loop.

    #!/usr/bin/env bash
    
    ## Writting a until d into the file file01 and writing 1 until 3 into the file file02.
    echo {a..d} | tee file01
    echo {1..3} | tee file02
    
    ## Declaring two arrays (FILE01 and FILE02) and a variable as integer.
    declare -a FILE01=($(

    declare -a -> It creates an array

    declare -i -> It declares the var as integer

    ${#FILE01[@]} -> It's to get the array size

提交回复
热议问题