Dasel: Difference between revisions
From wikinotes
(→XML) |
(→XML) |
||
Line 61: | Line 61: | ||
# <configuration><device>...</device></configuration> with <a>1</a> | # <configuration><device>...</device></configuration> with <a>1</a> | ||
cat config.xml \ | cat config.xml \ | ||
| dasel put -r xml | | dasel put -r xml -v '<a>1</a>' \ | ||
'.configuration.device' | '.configuration.device' | ||
Line 67: | Line 67: | ||
# <configuration><device>...</device></configuration> with <a>1</a> | # <configuration><device>...</device></configuration> with <a>1</a> | ||
cat config.xml \ | cat config.xml \ | ||
| dasel put -r xml | | dasel put -r xml -v '<a>1</a>' \ | ||
'.configuration.device.[0]' | '.configuration.device.[0]' | ||
Revision as of 04:54, 29 January 2023
Inspired by jq and yq, but operates on json, yaml, toml, xml, csv.
Totally standalone, no runtime dependencies.
I'm not certain you can append to a list,
Documentation
official docs https://daseldocs.tomwright.me/ github https://github.com/TomWright/dasel
Examples
# modify 'foo.yml', adding obj['category']['three'] = "3" dasel put string \ -f foo.yml \ '.category.three' '3' # print 'foo.yml', # with obj['category']['three'] = "3" added, # while also preserving comments # # see: https://stackoverflow.com/questions/14282617/hunk-1-failed-at-1-whats-that-mean diff \ <(dasel -f foo.yml) \ <(dasel put string -f foo.yml -o - '.category.three' '3') \ | patch -o - foo.yml
Datatypes
string: string int: integer bool: true/false object: a set of key/value pairs (can be assigned to objects of various types) document: a json/yaml/toml/... object (can be put into documents of other types)
File Formats
CSV
cat out.csv | dasel -p csv -m '.-'
XML
See https://github.com/TomWright/dasel-docs/blob/master/examples/xml.md
# REPLACE the contents of the LAST # <configuration><device>...</device></configuration> with <a>1</a> cat config.xml \ | dasel put -r xml -v '<a>1</a>' \ '.configuration.device' # REPLACE the contents of the FIRST # <configuration><device>...</device></configuration> with <a>1</a> cat config.xml \ | dasel put -r xml -v '<a>1</a>' \ '.configuration.device.[0]' # APPEND a new element cat config.xml \ | dasel put -r xml -v '<a>1</a>' \ '.configuration.device.append()'