Delimiter
Syntax
Section titled “Syntax”The delimiter is a plain argument — no flag needed:
splitby "/REGEX/" [selection...]splitby "LITERAL" [selection...]Use -d / --delimiter when the delimiter would otherwise be ambiguous:
splitby -d "/REGEX/" [selection...]splitby --delimiter="LITERAL" [selection...]What it does
Section titled “What it does”Splits each record into fields. The delimiter is the first argument that isn’t a flag or a selection.
When to use -d
Section titled “When to use -d”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
echo "1 2 3" | splitby -d "1" 2 # "1" would be parsed as a selection without -decho "a-b-c" | splitby -d "-" 2 # "-" would error as an invalid flag without -dExamples
Section titled “Examples”Split on a literal comma:
echo "a,b,c" | splitby "," 2# bSplit on regex whitespace:
echo "a b c" | splitby "/\\s+/" 3# cGotchas
Section titled “Gotchas”- Shells often eat backslashes. Use single quotes or double-escape (
'\\s+'). - If a delimiter has already been set, implicit delimiters will instead error.