The yq is a command line based YAML processor which can be used to manipulate and extract values from YAML data.
This tutorial demonstrates how to install yq on Raspberry Pi.
Install yq
Use SSH to connect to Raspberry Pi. Run the following command to 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_arm
Set execute permission:
sudo chmod a+x /usr/local/bin/yq
Now yq
command can be used for all users as a system-wide command.
We can check version of yq:
yq --version
Testing yq
Create test.yaml
file:
printf "status: success\ndata:\n - name: John\n age: 25\n - name: James\n age: 29" > test.yaml
The yq allows to use expression to filter YAML data. Each different part in expression is separated by a dot (.
). For example, the following command outputs unmodified YAML:
yq e '.' test.yaml
Output:
status: success
data:
- name: John
age: 25
- name: James
age: 29
Particular value in YAML data can be retrieved as follows:
yq e '.data[1].name' test.yaml
Output:
James
Uninstall yq
If you wish to remove yq, delete executable file:
sudo rm -rf /usr/local/bin/yq
Leave a Comment
Cancel reply