mirror of
https://github.com/nushell/nushell
synced 2025-01-13 13:49:21 +00:00
add documentation for format
This commit is contained in:
parent
340e701124
commit
3fb4a5d6e6
1 changed files with 37 additions and 0 deletions
37
docs/commands/format.md
Normal file
37
docs/commands/format.md
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# format
|
||||||
|
|
||||||
|
Format columns into a string using a simple pattern
|
||||||
|
|
||||||
|
Syntax: `format <pattern>`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `<pattern>`: the pattern to match
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Let's say we have a table like this:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> open pets.csv
|
||||||
|
━━━┯━━━━━━━━━━━┯━━━━━━━━┯━━━━━
|
||||||
|
# │ animal │ name │ age
|
||||||
|
───┼───────────┼────────┼─────
|
||||||
|
0 │ cat │ Tom │ 7
|
||||||
|
1 │ dog │ Alfred │ 10
|
||||||
|
2 │ chameleon │ Linda │ 1
|
||||||
|
━━━┷━━━━━━━━━━━┷━━━━━━━━┷━━━━━
|
||||||
|
```
|
||||||
|
|
||||||
|
`format` allows us to convert table data into a string by following a formatting pattern. To print the value of a column we have to put the column name in curly brackets:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> open pets.csv | format "{name} is a {age} year old {animal}"
|
||||||
|
━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
# │ <value>
|
||||||
|
───┼─────────────────────────────────
|
||||||
|
0 │ Tom is a 7 year old cat
|
||||||
|
1 │ Alfred is a 10 year old dog
|
||||||
|
2 │ Linda is a 1 year old chameleon
|
||||||
|
━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
```
|
Loading…
Reference in a new issue