This commit is contained in:
Mike Farah 2024-02-16 09:55:01 +11:00
parent 5edabcf934
commit b2965d58a6
2 changed files with 46 additions and 7 deletions

View File

@ -136,13 +136,13 @@ Samantha's Rabbit,,-188.8
```
## 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:
```csv
name,numberOfCats,likesApples,height
Gary,1,true,168.8
Samantha's Rabbit,2,false,-188.8
name,numberOfCats,likesApples,height,facts
Gary,1,true,168.8,cool: true
Samantha's Rabbit,2,false,-188.8,tall: indeed
```
then
@ -155,10 +155,42 @@ will output
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 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

View File

@ -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 `# comments` to explain things
```bash
yq --inplace '
with(.a.deeply.nested;
. = "newValue" | . style="single") |
with(.a.deeply.nested;
. = "newValue" | . style="single" # line comment about styles
) |
#
# Block comment that explains what is happening.
#
with(.b.another.nested;
. = "cool" | . style="folded")
. = "cool" | . style="folded"
)
' my_file.yaml
```