Home Explore Blog CI



nushell

1st chunk of `commands/docs/from_csv.md`
b45610c5bde154ee44213f14c69a54f020f9003642f39b7e0000000100000b91
---
title: from csv
categories: |
  formats
version: 0.104.0
formats: |
  Parse text as .csv and create table.
usage: |
  Parse text as .csv and create table.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `from csv` for [formats](/commands/categories/formats.md)

<div class='command-title'>Parse text as .csv and create table.</div>

## Signature

```> from csv {flags} ```

## Flags

 -  `--separator, -s {string}`: a character to separate columns (either single char or 4 byte unicode sequence), defaults to ','
 -  `--comment, -c {string}`: a comment character to ignore lines starting with it
 -  `--quote, -q {string}`: a quote character to ignore separators in strings, defaults to '"'
 -  `--escape, -e {string}`: an escape character for strings containing the quote character
 -  `--noheaders, -n`: don't treat the first row as column names
 -  `--flexible`: allow the number of fields in records to be variable
 -  `--no-infer`: no field type inferencing
 -  `--trim, -t {string}`: drop leading and trailing whitespaces around headers names and/or field values


## Input/output types:

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

Convert comma-separated data to a table
```nu
> "ColA,ColB
1,2" | from csv
╭───┬──────┬──────╮
│ # │ ColA │ ColB │
├───┼──────┼──────┤
│ 0 │    1 │    2 │
╰───┴──────┴──────╯

```

Convert comma-separated data to a table, allowing variable number of columns per row
```nu
> "ColA,ColB
1,2
3,4,5
6" | from csv --flexible
╭───┬──────┬──────┬─────────╮
│ # │ ColA │ ColB │ column2 │
├───┼──────┼──────┼─────────┤
│ 0 │    1 │    2 │   ❎    │
│ 1 │    3 │    4 │       5 │
│ 2 │    6 │  ❎  │   ❎    │
╰───┴──────┴──────┴─────────╯

```

Convert comma-separated data to a table, ignoring headers
```nu
> open data.txt | from csv --noheaders

```

Convert semicolon-separated data to a table
```nu
> open data.txt | from csv --separator ';'

```

Convert comma-separated data to a table, ignoring lines starting with '#'
```nu
> open data.txt | from csv --comment '#'

```

Convert comma-separated data to a table, dropping all possible whitespaces around header names and field values
```nu
> open data.txt | from csv --trim all

```

Convert comma-separated data to a table, dropping all possible whitespaces around header names
```nu
> open data.txt | from csv --trim headers

```

Convert comma-separated data to a table, dropping all possible whitespaces around field values
```nu
> open data.txt | from csv --trim fields

```

Title: from csv
Summary
The `from csv` command in Nushell is used to parse text formatted as CSV (Comma Separated Values) and convert it into a Nushell table. It supports various flags to customize the parsing, such as specifying the separator, comment character, quote character, escape character, whether to treat the first row as headers, allowing variable number of fields, disabling type inference and trimming whitespaces. The command takes a string as input and outputs a table.