March 2018
Beginner to intermediate
416 pages
9h 24m
English
The split function splits the str string using a field separator specified using regex and stores it into the arr array. It returns the number of array elements created on splitting the string. If no separator is specified, then the string is split using the current field separator (FS) value. The following example illustrates the usage of the split function:
$ vi split1.awkBEGIN { string = "one-two-three-four" regex = "-" n = split ( string, arr, regex ) print "Array contains the following values: " for ( i=1; i<=n; i++ ) { printf("arr[%d] : %s\n", i, arr[i]) }}$ awk -f split1.awk
The output of the execution of the previous code is as follows:
Array contains the following values: arr[1] : onearr[2] : ...
Read now
Unlock full access