The yq is a command line based YAML processor which allows manipulating and extract values from YAML data.
This tutorial demonstrates how to install yq on Ubuntu 22.04.
Download the latest executable file of yq from GitHub:
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
Set execute permission for file:
sudo chmod a+x /usr/local/bin/yq
yq command is available for all users as a system-wide command.
We can check yq version:
test.yaml file for testing:
printf "status: success\ndata:\n - name: John\n age: 25\n - name: James\n age: 29" > test.yaml
The yq uses an expression to filter YAML data. Each different part in expression is separated by a dot (
.). For example, the following command prints unchanged YAML:
yq e '.' test.yaml
The output of the command:
status: success data: - name: John age: 25 - name: James age: 29
We can retrieve a particular value in YAML data as follows:
yq e '.data.name' test.yaml
If you decided to remove yq, delete executable file:
sudo rm -rf /usr/local/bin/yq