awk opposite of split

后端 未结 5 940
执笔经年
执笔经年 2021-01-12 04:03

what would be an opposite of split() in awk? Imagine I have array containig characters/integers.

What I\'ve tried:

color =          


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 05:09

    Here's a solution that doesn't rely on gawk or knowing the length of the array and lets you put a separator (space in this case) string between each array element if you like:

    color = "#FFFF00"
    printf "color original: %s\n", color
    split(color, chars, "")
    joined = sep = ""
    for (i=1; i in chars; i++) {
        joined = joined sep chars[i]
        sep = " "     # populate sep here with whatever string you want between elements
    }
    printf "color joined: %s\n", joined
    

    I also cleaned up the incorrect use of printf and the spurious semi-colons.

提交回复
热议问题