字符串分割

Table of Contents

shell

str="hello,world,i,like,you,babalala"  
arr=(${str//,/ })  

for i in ${arr[@]}
do
    echo $i
done

awk

echo "a,b,c" | awk '{split($0, a, ","); for(i in a) {print i, a[i]; }}'

perl

perl -e '@arr = split(/,/, $ARGV[0]);  foreach $key (keys @arr) { print $key."->".$arr[$key]."\n"; }

Author: josephzeng (josephzeng36@gmail.com)

Last Updated 2015-12-20. Created by Emacs 24.5.1 (Org mode 8.2.10)

Validate