Skip to content

Delimiter

The delimiter is a plain argument — no flag needed:

Terminal window
splitby "/REGEX/" [selection...]
splitby "LITERAL" [selection...]

Use -d / --delimiter when the delimiter would otherwise be ambiguous:

Terminal window
splitby -d "/REGEX/" [selection...]
splitby --delimiter="LITERAL" [selection...]

Splits each record into fields. The delimiter is the first argument that isn’t a flag or a selection.

Most of the time you don’t need it. The -d flag exists for cases where your delimiter would be parsed as something else:

  • Looks like a selection (e.g., 1, 2-3, last)
  • Starts with - and could be mistaken for a flag
Terminal window
echo "1 2 3" | splitby -d "1" 2 # "1" would be parsed as a selection without -d
echo "a-b-c" | splitby -d "-" 2 # "-" would error as an invalid flag without -d

Split on a literal comma:

Terminal window
echo "a,b,c" | splitby "," 2
# b

Split on regex whitespace:

Terminal window
echo "a b c" | splitby "/\\s+/" 3
# c
  • Shells often eat backslashes. Use single quotes or double-escape ('\\s+').
  • If a delimiter has already been set, implicit delimiters will instead error.