Samir
Samir

Reputation: 21

split string based on delimeter and put them into array using bash script

What is a simple way to split a string and put into an array Here is my string

aa_bb__cc_dd

I would like to have them in an array like this:

array[0] = "aa"

array[1] = "bb"

array[2] = ""

array[3] = "cc"

array[4] = "dd"

Upvotes: 2

Views: 428

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64308

var=aa_bb__cc_dd
oldIFS=$IFS
IFS=_
array=($var)
IFS=$oldIFS

Upvotes: 5

Related Questions