But there are some special formats of files which have a concrete structure, and we can extract meaning from its structure. For example CSV.
JQ
jq is like sed for json files. It allows you to parse, grep, replace, match and join json files. For example, /tmp/issues.json being the output of a github repo issues:cat /tmp/issues.json | jq '.[] |select(.labels[].name | in({"S-zendesk": 12})) | {labels: [.labels[].name | match("^A-.*") | .string] }'
Select issues which have label S-zendesk, and pick the label A-* of it. To know which are the areas that have zendesk issues.
Xmlstarlet
Xmlstarlet is the same as jq but for xml. Allows you to print and match fields from xmls. For an xml file like this:We can list title of files and id's with:
cat files.xml | xmlstarlet sel -T -t -m 'files/file' -v 'title' -o ' => ' -v 'id' -n
No hay comentarios:
Publicar un comentario