Tips for working with bash
While you are doing awesome stuff, some noisy things bother you. The following tips might help you out.
Skip the first line from output
You want to skip the first line from the output for parsing JSON with jq command.
$ cat <<EOF
skip me please
{
"hello": "world"
}
EOF
You can do it with awk
- a utility tool installed in many Linux distributions. It includes a built-in row number variable NR
to skip.
For example, NR>1
is an action to skip a 1 row from the beginning.
$ cat <<EOF |awk "NR>1" |jq
skip me please
{
"hello": "world"
}
EOF
Now, the JSON output can be parsed by jq
{
"hello": "world"
}
Print all docker images with its tag
docker images |awk 'NR>1 {print $1":"$2}'
NR>1
skips thedocker images
output headerREPOSITORY:TAG
- Concatenate 2 columns with
":"