Home Explore Blog CI



nushell

1st chunk of `cookbook/parsing.md`
6ffdfb8a1673279363c144992f8ad3797889ebf5b85cf8e70000000100000c9b
---
title: Parsing
---

# Parsing

*Nu* offers the ability to do some basic parsing, with different ways to achieve the same goal.

Builtin-functions that can be used include:

- `lines`
- `detect columns`
- `parse`
- `str ...`
- `from ssv`

A few illustrative examples follow.

## Examples (tabular output)

### `detect columns` (pretty automatic)

```nu
df -h | str replace "Mounted on" Mounted_On | detect columns
# => ╭────┬───────────────────────────────────┬──────┬──────┬───────┬──────┬────────────────────────────────────╮
# => │  # │            Filesystem             │ Size │ Used │ Avail │ Use% │             Mounted_On             │
# => ├────┼───────────────────────────────────┼──────┼──────┼───────┼──────┼────────────────────────────────────┤
# => │  0 │ devtmpfs                          │ 3.2G │ 0    │ 3.2G  │ 0%   │ /dev                               │
# => │  1 │ tmpfs                             │ 32G  │ 304M │ 32G   │ 1%   │ /dev/shm                           │
# => │  2 │ tmpfs                             │ 16G  │ 11M  │ 16G   │ 1%   │ /run                               │
# => │  3 │ tmpfs                             │ 32G  │ 1.2M │ 32G   │ 1%   │ /run/wrappers                      │
# => │  4 │ /dev/nvme0n1p2                    │ 129G │ 101G │ 22G   │ 83%  │ /                                  │
# => │  5 │ /dev/nvme0n1p8                    │ 48G  │ 16G  │ 30G   │ 35%  │ /var                               │
# => │  6 │ efivarfs                          │ 128K │ 24K  │ 100K  │ 20%  │ /sys/firmware/efi/efivars          │
# => │  7 │ tmpfs                             │ 32G  │ 41M  │ 32G   │ 1%   │ /tmp                               │
# => │  9 │ /dev/nvme0n1p3                    │ 315G │ 230G │ 69G   │ 77%  │ /home                              │
# => │ 10 │ /dev/nvme0n1p1                    │ 197M │ 120M │ 78M   │ 61%  │ /boot                              │
# => │ 11 │ /dev/mapper/vgBigData-lvBigData01 │ 5.5T │ 4.1T │ 1.1T  │ 79%  │ /bigdata01                         │
# => │ 12 │ tmpfs                             │ 1.0M │ 4.0K │ 1020K │ 1%   │ /run/credentials/nix-serve.service │
# => │ 13 │ tmpfs                             │ 6.3G │ 32M  │ 6.3G  │ 1%   │ /run/user/1000                     │
# => ╰────┴───────────────────────────────────┴──────┴──────┴───────┴──────┴────────────────────────────────────╯

Title: Parsing in Nu
Summary
Nu provides several built-in functions for parsing text, including `lines`, `detect columns`, `parse`, `str ...`, and `from ssv`. The `detect columns` command can automatically parse tabular data, as demonstrated by the `df -h` example.