Awk split use array later in bash -


if have awk command...

echo $line | awk '{split($0,array,"|")}' 

...how can use array later in bash program? if try print out information array later it's empty.

you can use awk array contents outside of awk if print it:

ifs=$'\n' read -d '' -r -a line < <(echo 'o|p|s' | awk '{split($0,array,"|"); (i in array) print array[i]}') declare -p line # output: declare -a line='([0]="o" [1]="p" [2]="s")' 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -