mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 11:55:38 +00:00
v4.41.1
This commit is contained in:
parent
5edabcf934
commit
b2965d58a6
@ -136,13 +136,13 @@ Samantha's Rabbit,,-188.8
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Parse CSV into an array of objects
|
## Parse CSV into an array of objects
|
||||||
First row is assumed to be the header row.
|
First row is assumed to be the header row. By default, entries with YAML/JSON formatting will be parsed!
|
||||||
|
|
||||||
Given a sample.csv file of:
|
Given a sample.csv file of:
|
||||||
```csv
|
```csv
|
||||||
name,numberOfCats,likesApples,height
|
name,numberOfCats,likesApples,height,facts
|
||||||
Gary,1,true,168.8
|
Gary,1,true,168.8,cool: true
|
||||||
Samantha's Rabbit,2,false,-188.8
|
Samantha's Rabbit,2,false,-188.8,tall: indeed
|
||||||
|
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -155,10 +155,42 @@ will output
|
|||||||
numberOfCats: 1
|
numberOfCats: 1
|
||||||
likesApples: true
|
likesApples: true
|
||||||
height: 168.8
|
height: 168.8
|
||||||
|
facts:
|
||||||
|
cool: true
|
||||||
- name: Samantha's Rabbit
|
- name: Samantha's Rabbit
|
||||||
numberOfCats: 2
|
numberOfCats: 2
|
||||||
likesApples: false
|
likesApples: false
|
||||||
height: -188.8
|
height: -188.8
|
||||||
|
facts:
|
||||||
|
tall: indeed
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parse CSV into an array of objects, no auto-parsing
|
||||||
|
First row is assumed to be the header row. Entries with YAML/JSON will be left as strings.
|
||||||
|
|
||||||
|
Given a sample.csv file of:
|
||||||
|
```csv
|
||||||
|
name,numberOfCats,likesApples,height,facts
|
||||||
|
Gary,1,true,168.8,cool: true
|
||||||
|
Samantha's Rabbit,2,false,-188.8,tall: indeed
|
||||||
|
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq -p=csv --csv-auto-parse=f sample.csv
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
- name: Gary
|
||||||
|
numberOfCats: 1
|
||||||
|
likesApples: true
|
||||||
|
height: 168.8
|
||||||
|
facts: 'cool: true'
|
||||||
|
- name: Samantha's Rabbit
|
||||||
|
numberOfCats: 2
|
||||||
|
likesApples: false
|
||||||
|
height: -188.8
|
||||||
|
facts: 'tall: indeed'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parse TSV into an array of objects
|
## Parse TSV into an array of objects
|
||||||
|
@ -14,12 +14,19 @@ Feel free to use multiple lines in your expression to improve readability.
|
|||||||
|
|
||||||
Use `with` if you need to make several updates to the same path.
|
Use `with` if you need to make several updates to the same path.
|
||||||
|
|
||||||
|
Use `# comments` to explain things
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq --inplace '
|
yq --inplace '
|
||||||
with(.a.deeply.nested;
|
with(.a.deeply.nested;
|
||||||
. = "newValue" | . style="single") |
|
. = "newValue" | . style="single" # line comment about styles
|
||||||
|
) |
|
||||||
|
#
|
||||||
|
# Block comment that explains what is happening.
|
||||||
|
#
|
||||||
with(.b.another.nested;
|
with(.b.another.nested;
|
||||||
. = "cool" | . style="folded")
|
. = "cool" | . style="folded"
|
||||||
|
)
|
||||||
' my_file.yaml
|
' my_file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user