Shyaml: Process YAML in the command line

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.