Search

Dark theme | Light theme

December 2, 2026

Nushell Niceties: Change Order Of Columns In Tables With move

Tables are one of the core data structures in Nushell. Each table has columns and rows. You can use the move command to reorganize the order of columns in a table. You can specify one or more columns to be moved and those are specified before the move command. With the options --after and --before you can specify the column that the other columns need to be moved after or before. To move one or more columns to be the first columns of the table you must use the --first option. And to make column(s) the last columns you can use --last.

In the following example the move command is used with different options and different number of columns:

use std/assert

# Sample table.
let table = [
  [a b c];
  [1 a A]
  [2 b B]
]


# Use move to move columns a and b
# with option --after.
(assert equal ($table | move a --after b)
[
  [b a c];
  [a 1 A]
  [b 2 B]
])

# Use move to move multiple columns
# with option --after.
# Ordering of the columns can be changed.
(assert equal ($table | move a b --after c)
[
  [c a b];
  [A 1 a]
  [B 2 b]
])

# Use move to move multiple columns
# with option --after.
# Ordering of the columns can be changed.
(assert equal ($table | move b a --after c)
[
  [c b a];
  [A a 1]
  [B b 2]
])


# Use move to move columns a and b
# with option --before.
(assert equal ($table | move b --before a)
[
  [b a c];
  [a 1 A]
  [b 2 B]
])

# Use move to move multiple columns
# with option --before.
# Ordering of the columns can be changed.
(assert equal ($table | move c b --before a)
[
  [c b a];
  [A a 1]
  [B b 2]
])

# Use move to move multiple columns
# with option --before.
# Ordering of the columns can be changed.
(assert equal ($table | move b c --before a)
[
  [b c a];
  [a A 1]
  [b B 2]
])


# Use move to move columns to be the first column
# with option --first.
(assert equal ($table | move b --first)
[
  [b a c];
  [a 1 A]
  [b 2 B]
])

# Use move to move multiple columns to be the first columns
# with option --first.
(assert equal ($table | move b c --first)
[
  [b c a];
  [a A 1]
  [b B 2]
])

# Use move to move columns to be the last column
# with option --last.
(assert equal ($table | move b --last)
[
  [a c b];
  [1 A a]
  [2 B b]
])

# Use move to move multiple columns to be the last columns
# with option --last.
(assert equal ($table | move a b --last)
[
  [c a b];
  [A 1 a]
  [B 2 b]
])

Written with Nushell 0.117.0.