Join
Syntax
Section titled “Syntax”splitby --join "<STRING>" [selection...]What it does
Section titled “What it does”By default, splitby tries to preserve the original delimiter between selections in field mode. --join replaces that behavior with your custom string.
Because delimiters can be regex, sometimes there are multiple delimiters in a record. Join also accepts a number of special keywords to help you choose which you want.
auto: Apply the default behaviour of tryingafter-previous, then tryingbefore-nextthen falling back to a space.first: Use the first delimiter in the recordlast: Use the last delimiter in the recordafter-previous: Use the delimiter after the previously printed fieldbefore-next: Use the delimiter before the next printed fieldspace: Use a single space, equivalent to" "none: Use an empty join, equivalent to""
Examples
Section titled “Examples”Custom string join
Section titled “Custom string join”Join selections with a custom string:
echo "a,b,c" | splitby -d "," --join " | " 1 3# a | cecho "apple,banana,cherry" | splitby -d "," -j " -> " 1-3# apple -> banana -> cherryJoin keywords
Section titled “Join keywords”Use special keywords:
auto (default behavior)
Section titled “auto (default behavior)”Tries to preserve original delimiters, falling back to space when no delimiter is available:
# When delimiters exist between selections, preserves themecho "apple,banana,cherry" | splitby -d "," --join auto 1 3# apple,cherry
# Falls back to space when no delimiter is availableecho "apple" | splitby -d "," --join auto 1 1# apple applefirst (first delimiter)
Section titled “first (first delimiter)”Uses the first delimiter found in the record:
echo "apple,banana;cherry:date" | splitby -d "/[,;:]/" --join first 3 4# cherry,datelast (last delimiter)
Section titled “last (last delimiter)”Uses the last delimiter found in the record:
# Multiple delimiter types - uses the last one foundecho "apple,banana;cherry:date" | splitby -d "/[,;:]/" --join last 1 2# apple:bananaafter-previous (delimiter after previous field)
Section titled “after-previous (delimiter after previous field)”Uses the delimiter that immediately follows the previously selected field:
# Uses the comma after "apple" (field 1)echo "apple,banana;cherry:date" | splitby -d "/[,;:]/" --join after-previous 1 3 1# apple,cherry:applebefore-next (delimiter before next field)
Section titled “before-next (delimiter before next field)”Uses the delimiter that immediately precedes the next selected field:
# Uses the comma before "cherry" (field 3)echo "apple,banana;cherry:date" | splitby -d "/[,;:]/" --join before-next 1 4 2# apple:date,banananone (no separator)
Section titled “none (no separator)”Concatenates selections with no separator between them:
echo "apple,banana,cherry" | splitby -d "," --join none 1 3# applecherryspace (single space)
Section titled “space (single space)”Always uses a single space, regardless of original delimiters:
# Original delimiter is comma, but output uses spaceecho "apple,banana,cherry" | splitby -d "," --join space 1 3# apple cherryGotchas
Section titled “Gotchas”after-previousandbefore-nextfallback to a space, if there is no delimiter available. I might change this depending on feedback.