Basics
What is it?
Section titled “What is it?”splitby splits text into fields and returns just the pieces you ask for.
echo "apple,banana,cherry" | splitby , 2# bananaDelimiters
Section titled “Delimiters”Delimiters are search strings that we split the text by. You can pass one explicitly:
echo "a b c" | splitby -d " " 2# bOr implicitly drop the flag, and splitby will detect it:
echo "a,b,c" | splitby , 1 3# a,cRegex delimiters
Section titled “Regex delimiters”Regex delimiters are also supported, by surrounding the string with forward slashes:
echo "a b c" | splitby -d "/\\s+/" 2# bSelections
Section titled “Selections”Selections are one-based indexes:
echo "a b c d" | splitby -d " " 1# aRanges work too:
echo "a b c d" | splitby -d " " 2-3# b cNegative indexes count from the end:
echo "a b c d" | splitby -d " " -1# dMultiple selections
Section titled “Multiple selections”You can list multiple selections with spaces:
echo "a b c d" | splitby -d " " 1 3-4# a c d