Home Explore Blog CI



nushell

1st chunk of `commands/docs/compact.md`
bcd0660f1fe6c2f8ee288b9a7a9de49c0fa96d1c03f39bb000000001000006df
---
title: compact
categories: |
  filters
version: 0.104.0
filters: |
  Creates a table with non-empty rows.
usage: |
  Creates a table with non-empty rows.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `compact` for [filters](/commands/categories/filters.md)

<div class='command-title'>Creates a table with non-empty rows.</div>

## Signature

```> compact {flags} ...rest```

## Flags

 -  `--empty, -e`: also compact empty items like "", {}, and []

## Parameters

 -  `...rest`: The columns to compact from the table.


## Input/output types:

| input     | output    |
| --------- | --------- |
| list\<any\> | list\<any\> |
## Examples

Filter out all records where 'Hello' is null
```nu
> [["Hello" "World"]; [null 3]] | compact Hello
╭────────────╮
│ empty list │
╰────────────╯

```

Filter out all records where 'World' is null
```nu
> [["Hello" "World"]; [null 3]] | compact World
╭───┬───────┬───────╮
│ # │ Hello │ World │
├───┼───────┼───────┤
│ 0 │       │     3 │
╰───┴───────┴───────╯

```

Filter out all instances of null from a list
```nu
> [1, null, 2] | compact
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯

```

Filter out all instances of null and empty items from a list
```nu
> [1, null, 2, "", 3, [], 4, {}, 5] | compact --empty
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
╰───┴───╯

```

Title: compact command in Nushell
Summary
The `compact` command in Nushell filters a table or list, removing rows or items that are considered empty (null values by default). It can be used with the `--empty` flag to also remove empty strings, empty lists, and empty objects. The command can operate on specific columns of a table or on the entire input list.