[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: split(): syntax error near unexpected token `(' ...



> What is "array" supposed to do?  [??]

> What did you want the script to do?
~
 chemie.fu-berlin.de/chemnet/use/info/gawk/gawk_13.html#SEC126
~
split(string, array [, fieldsep])
    This divides string into pieces separated by fieldsep, and stores
the pieces in 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). If the
fieldsep is omitted, the value of FS is used. split returns the number
of elements created. The split function splits strings into pieces in
a manner similar to the way input lines are split into fields. For
example:

    split("cul-de-sac", a, "-")

    splits the string `cul-de-sac' into three fields using `-' as the
separator. It sets the contents of the array a as follows:

    a[1] = "cul"
    a[2] = "de"
    a[3] = "sac"

    The value returned by this call to split is three. As with input
field-splitting, when the value of fieldsep is " ", leading and
trailing whitespace is ignored, and the elements are separated by runs
of whitespace. Also as with input field-splitting, if fieldsep is the
null string, each individual character in the string is split into its
own array element. (This is a gawk-specific extension.) Recent
implementations of awk, including gawk, allow the third argument to be
a regexp constant (/abc/), as well as a string (d.c.). The POSIX
standard allows this as well. Before splitting the string, split
deletes any previously existing elements in the array array (d.c.).
~
 lbrtchx


Reply to: