Alternate merge strings in BASH -


from

ks=$(locate acpi-support | grep "/etc/rc" | cut -f4 -d/ | tr -dc '[k,s]') levels=$(locate acpi-support | grep "/etc/rc" | cut -f3 -d/ | tr -dc '[0-9]') echo $ks echo $levels 

i following outputs:

kssss 12345 

what i'd merge alternatively previous outputs in way:

k1 s2 s3 s4 s5 

i tried whit nested for loops without success, how it?

you can use loop iterate on characters in 1 of strings , use bash's substring functionality print out characters. shown below:

ks="kssss" levels="12345" unset result (( i=0; i<${#ks}; i++ ));   result+="${ks:$i:1}${levels:$i:1} " done echo "$result" 

output:

k1 s2 s3 s4 s5 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -