bash - Split string in AWK using multi-character delimiter -


i have following delimiter , string:

del=":::" str="info1"$del"info2"$del"info3" 

i want extract info1-2-3 str using awk.

the following works:

info1=$(echo $str | awk '{split($0,a,":::")} end{print a[1]}') info2=$(echo $str | awk '{split($0,a,":::")} end{print a[2]}') info3=$(echo $str | awk '{split($0,a,":::")} end{print a[3]}') 

the following not work:

info1=$(echo $str | awk '{split($0,a,"$del")} end{print a[1]}') 

what's wrong?

since del shell variable, should using like:

info1=$(echo $str | awk -v delimeter="$del" '{split($0,a,delimeter)} end{print a[1]}') 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -