Parse text into user-defined variables.


splitline(text, delimiters, flag, variable_1,
variable_2, [...variable_n])





text that you want to parse


character(s) that separates the fields


one or more literal characters that affect the behavior of this function

*Valid Values* 
" " returns the number of fields placed into variables 
t returns the total number of fields that can be extracted 
a if the text can be parsed into more fields than the number of variables, the last variable contains all of the remaining text 
f consecutive occurrences of the delimiter are interpreted as individual fields (see description for more information)

variable_1, [variable_2,...variable_n ]

one or more user-defined variables to hold the extracted fields You can use a maximum of 97 variables. Define and initialize variables before using them with splitline(). This function ignores any literal strings passed as variables.


The splitline() function parses text into fields (based on delimiters) and assigns these fields to user-supplied variables. This function returns the number of fields saved to variables. See the flags parameter in the preceding table for more information about return values. 

The default behavior of splitline() is to interpret two or more consecutive delimiters as being a single delimiter. With the f flag, splitline() reads every occurrence of a delimiter as being the end of a field. For example, splitline() typically reads the following string as having three fields, "abc::123:xyz" (where ':' is the delimiter). With the f flag, splitline() reads the same string as having four fields, and the second field contains no data. Using the f flag with splitline() is similar to using the nthargf() function.


The following example demonstrates the splitline() function:

Data = cat("/etc/passwd");
foreach line x (Data) {
splitline(x, ":", "", User, Passwd, Uid);
printf("%s %d\n", User, Uid);


The following example shows the use of the f flag:

splitline("abc::123", ":", "", var_1, var_2, var_3);
print("Default:var 1=". var_1.", var 2=". var_2.",
var 3=". var_3);
splitline("abc::123", ":", "f", var_1, var_2, var_3);
print("\nf flag:var 1=". var_1.", var 2=". var_2.",
var 3=". var_3);

The following output was generated by the previous example:

Default:var 1=abc, var 2=123, 
var 3=f flag:var 1=abc, var 2=, var 3=123


Was this page helpful? Yes No Submitting... Thank you