Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or more generally any regexp as the separator)?
Obviously, one could use the internal autosplit (that runs on each line of the input with value of FS variable as the separator) and with simple for and $0 magic do the trick. However, I was just wondering if there’s a more straightforward way using the splititself.
The GNU Awk User’s Guide states:
Here is a short (somewhat silly) example that uses a simple regular expression
".s "that will match any single character followed by a lower-casesand a space. The result of the split is put into arraya. Note that the parts that match are not placed into the array.The output:
The article Advanced Awk for Sysadmins show an example of parsing a line using
split(). This page contains an example of using a regular expression to split data intoan array.