Shyaml: Process YAML in the command line
YAML is a friendly data exchange format for humans. If you need to process YAML in the Linux Command Line, use shyaml.
Through shyaml, you can directly obtain the key, value, key-value pair, or corresponding type. To install shyaml, run the following command:
pip install shyaml
Because shyaml reads YAML content from the standard input and prints the result to the standard output, its common usage is:
cat <file.yaml> | shyaml ACTION KEY [DEFAULT]
HereACTIONIt can be:
get-type: Get the corresponding type
get-value: Get value
get-values{,-0}: For the sequence type, obtain the Value List
keys{,-0}: Return key list
values{,-0}: Return Value List
key-values,{,-0}: Return key-value pairs
The result is added by default.\nLine Break. If-0The format isNULCharacter filling.
KEYIs the Key to be queried. If not, useDEFAULT.
For example, the content of our file. yaml file is:
---idc_group: name: bx bx: news_bx: news_bx web3_bx: web3_php-fpm_bx
If you want to obtainidc_group.nameCan be executed:
cat file.yaml | shyaml get-value idc_group.name
Want to getidc_group.bxCan be executed:
cat file.yaml | shyaml key-values idc_group.bx
If you want to process JSON data in the Linux Command Line, I strongly recommend jq as a useful tool.
Jq: Process JSON from the command line
→ Shyaml
This article permanently updates the link address: