Search

Dark theme | Light theme

July 28, 2026

Nushell Niceties: Splitting String Values Into A Table

You can use the split column command to split a string value or a list of string values into a table. You need to specify a delimiter to split the value on. In the resulting table the elements are stored in columns. By default the columns have the name column<index> where index is the number of the column starting with 0. It is possible to define your own column names by specifying their names as parameters for the split column command. This way the resulting table will have more meaningful names.

In the following example you can see how to use split column with a simple delimiter:

use std/assert

# Example string value to split.
let project = "JIRA-42"

# With split column you need to specify the delimiter value to
# split on.
# In the following example the delimiter is a hyphen.
assert equal ($project | split column '-') [{column0: "JIRA" column1: "42"}]

# You can specify the names of the columns in the result
# with extra arguments. In this example prj and issue
# are used as column names.
assert equal ($project | split column '-' prj issue) [{prj: "JIRA" issue: "42"}]

# Columns are empty when no value is available after the split.
assert equal ('JIRA-' | split column '-' prj issue) [{prj: 'JIRA' issue: ''}]

# You can use the option --collapse-empty to remove the empty columns
# from the result.
assert equal ('JIRA-' | split column --collapse-empty '-' prj issue) [{prj: 'JIRA'}]

It is possible to specify the number of columns that should be returned regardless of how many columns are returned by using the split delimiter. This means that in the result the last column could have a value that still has a delimiter. With the extra option --right the first column is used as the column to store the elements with an optionally delimiter value.

The use of the --number (or -n) and --right options is shown in the following example:

use std/assert

# Example string value to split.
let dependency = "org.springframework.boot:spring-boot:4.1.0"

# Delimiter is a colon.
(assert equal
  ($dependency | split column ':' group artifact version)
  [{group: "org.springframework.boot" artifact: "spring-boot" version: "4.1.0"}])

# You can use the option --number (or -n) to define
# the number of columns the split should result in.
# The last column contains the "rest" of the elements with
# possibly the delimiter value.
(assert equal
  ($dependency | split column --number 2 ':' c1 c2)
  [{c1: "org.springframework.boot" c2: "spring-boot:4.1.0"}])


# You can combine --number (or -n) with --right and then the first column
# will have the "rest" of the elements and possibly containing the delimiter.
(assert equal
  ($dependency | split column --number 2 --right ':' c1 c2)
  [{c1: "org.springframework.boot:spring-boot" c2: "4.1.0"}])

Instead of using a string delimiter it is possible to use a regular expression. You have to use the command option --regex or the short-hand -r followed by the regular expression.

A simple example of using the the --regex (or -r) option:

use std/assert

# To use a regular expression to split the option --regex (or -r)
# can be used. In the following example any number of space
# characters is used to split.
(assert equal
  ("a b  c d   e" | split column --regex '\s+' c1 c2 c3 c4 c5)
  [{c1: "a" c2: "b" c3: "c" c4: "d" c5: "e"}])

All the options mentioned above are also applicable when the input is a list of string values.

In the following example the split column command is used for a list of string values:

use std/assert

# Instead of splitting on a single string value
# the same command can be used on a list with string values.
let issues = ['JIRA-42' 'JIRA-101' 'JIRA-']

(assert equal
  ($issues | split column '-' --collapse-empty prj issue)
    [{prj: 'JIRA' issue: '42'}
     {prj: 'JIRA' issue: '101'}
     {prj: 'JIRA'}])

Written with Nushell 0.114.1.