I have a variable which consists of a string like this:
001 aaabc 44 a bbb12
How do I extract each substring, delimited by the spaces, into new variables - one for each substring?
eg var1 will be 001, var2 will be aaabc, var3 will be 44, var4 will be a, etc?
I've come up with this:
var1=$(echo $string | awk 'NF=1') ; var2=$(echo $string | awk 'NF=2') ; var3=$(echo $string | awk 'NF=3')
but var2 = NF1 and 2, var3 = NF 1,2,3 etc
It also seems a bit long winded and impractical for operating on a lengthy string.