Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

detect columns for strings

Attempt to automatically split text into multiple columns.

Signature

> detect columns {flags}

Flags

  • --skip, -s {int}: number of rows to skip before detecting
  • --no-headers, -n: don't detect headers
  • --ignore-box-chars, -i: ignore lines consisting entirely of box drawing characters and clean box characters from tokens
  • --combine-columns, -c {range}: columns to be combined; listed as a range
  • --guess: detect columns by guessing width, it may be useful if default one doesn't work

Input/output types:

inputoutput
stringtable
tabletable

Examples

use --guess if you find default algorithm not working

>
'Filesystem     1K-blocks      Used Available Use% Mounted on
none             8150224         4   8150220   1% /mnt/c' | detect columns --guess
╭───┬────────────┬───────────┬──────┬───────────┬──────┬────────────╮
│ # │ Filesystem │ 1K-blocks │ Used │ Available │ Use% │ Mounted on │
├───┼────────────┼───────────┼──────┼───────────┼──────┼────────────┤
│ 0 │ none       │ 8150224   │ 4    │ 8150220   │ 1%   │ /mnt/c     │
╰───┴────────────┴───────────┴──────┴───────────┴──────┴────────────╯

detect columns with no headers

> 'a b c' | detect columns  --no-headers
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ a       │ b       │ c       │
╰───┴─────────┴─────────┴─────────╯
> $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns 0..1

Splits a multi-line string into columns with headers detected

> $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns -2..-1

Splits a multi-line string into columns with headers detected

> $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns 2..

Parse external ls command and combine columns for datetime

> ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7

Table literal input is passed through unchanged

> [[name, age]; [Alice, 25]] | detect columns
╭───┬───────┬─────╮
│ # │ name  │ age │
├───┼───────┼─────┤
│ 0 │ Alice │  25 │
╰───┴───────┴─────╯

List of records input is passed through unchanged

> [{name: Alice, age: 25}, {name: Bob, age: 30}] | detect columns
╭───┬───────┬─────╮
│ # │ name  │ age │
├───┼───────┼─────┤
│ 0 │ Alice │  25 │
│ 1 │ Bob   │  30 │
╰───┴───────┴─────╯

Parse a box-bordered table by ignoring separator lines and using header positions

> "+-------+-------+
| col1  | col2  |
+-------+-------+
| a     | b     |
+-------+-------+" | detect columns --ignore-box-chars
╭───┬──────┬──────╮
│ # │ col1 │ col2 │
├───┼──────┼──────┤
│ 0 │ a    │ b    │
╰───┴──────┴──────╯