Home Explore Blog CI



nushell

commands/docs/detect_columns.md
f8cdc6fe76369d555e1b8802ad3f0c0f60c86c367e88042b0000000300000bbf
---
title: detect columns
categories: |
  strings
version: 0.104.0
strings: |
  Attempt to automatically split text into multiple columns.
usage: |
  Attempt to automatically split text into multiple columns.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `detect columns` for [strings](/commands/categories/strings.md)

<div class='command-title'>Attempt to automatically split text into multiple columns.</div>

## Signature

```> detect columns {flags} ```

## Flags

 -  `--skip, -s {int}`: number of rows to skip before detecting
 -  `--no-headers, -n`: don't detect headers
 -  `--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:

| input  | output |
| ------ | ------ |
| string | table  |
## Examples

use --guess if you find default algorithm not working
```nu
>
'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
```nu
> 'a b c' | detect columns  --no-headers
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ a       │ b       │ c       │
╰───┴─────────┴─────────┴─────────╯

```


```nu
> $'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
```nu
> $'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
```nu
> $'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
```nu
> ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7

```

Chunks
a0d96047 (1st chunk of `commands/docs/detect_columns.md`)
Title: detect columns command
Summary
The `detect columns` command in Nushell attempts to automatically split a string into multiple columns, creating a table. It supports options like skipping rows, disabling header detection, combining columns, and using a guessing algorithm for column width detection. The command takes a string as input and outputs a table.