dúvida em relação ao uso da divisão no awk

1
arr=($(echo "great#man" | awk  '{split($0,a,"#"); } END {print a[0]; print a[1];}')) 
    echo " ${arr[0]} "
    echo " ${arr[1]}"

Minha saída esperada é:

great
man

Mas estou recebendo

great

arr [1] não está sendo impresso

    
por user2179293 17.09.2013 / 09:44

1 resposta

3

Essa variação funciona para mim:

$ echo "great#man" | awk '{split($0,a,"#"); } END {print a[1]; print a[2];}'
great
man

Na documentação on-line :

split(string, array [, fieldsep [, seps ] ])

Divide string into pieces separated by fieldsep and store the pieces in array and the separator strings in the seps array. The first piece is stored in array[1], the second piece in array[2], and so forth. The string value of the third argument, fieldsep, is a regexp describing where to split string (much as FS can be a regexp describing where to split input records; see Regexp Field Splitting). If fieldsep is omitted, the value of FS is used. split() returns the number of elements created. seps is a gawk extension with seps[i] being the separator string between array[i] and array[i+1]. If fieldsep is a single space then any leading whitespace goes into seps[0] and any trailing whitespace goes into seps[n] where n is the return value of split() (that is, the number of elements in array).

    
por 17.09.2013 / 10:08

Tags