jq is like sed for JSON data — you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.
Flag | Usage |
---|---|
-c --compact-output | By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line. |
-M --monochrome-output | disable color : by default, jq outputs colored JSON if writing to a terminal |
-r --raw-output | output string without quotes |
resultFile='./result.json' taigaApiUrl='https://taiga.example.com/api/v1' taigaProjectId='2949' username='bob' password='123456789' authToken=$(curl -s --noproxy "*" --insecure -X POST -H "Content-Type: application/json" -d '{ "username": "'$username'", "password": "'$password'", "type": "normal" }' "$taigaApiUrl/auth" | jq -r '.auth_token') [ -f "$resultFile" ] && rm "$resultFile" curl -s --noproxy "*" --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${authToken}" "$taigaApiUrl/userstories?project=$taigaProjectId" > "$resultFile" # source : http://bigdatums.net/2017/05/13/count-json-array-elements-with-jq/ nbUserStories=$(jq '. | length' "$resultFile") echo "'$nbUserStories' user stories" # List the user stories IDs : # jq '.[29].ref' result.json # for i in {0..29}; do jq ".[$i].ref" result.json; done # [] is an iterator, no need of 'for' loop \o/ # https://stedolan.github.io/jq/manual/#Basicfilters #jq '.[].ref' result.json #jq ".[].subject" result.json # to get both : # source : https://stackoverflow.com/questions/28164849/using-jq-to-parse-and-display-multiple-fields-in-a-json-serially#answer-31418194 #jq -r '.[] | "\(.ref) ==> \(.subject)"' result.json # get tags : # thanks to : https://stackoverflow.com/questions/41712363/basic-jq-usage-how-to-get-nested-value #jq -r '.[].tags | .[] | .[0]' result.json echo 'Tags :' jq -r '.[].tags | .[] | .[]' "$resultFile" | sed '/^null$/d' | sort | uniq -c | sort -nr
To read all journals as a non-root user, you can either :
Field | Usage | example | Comments |
---|---|---|---|
MESSAGE=message | The human-readable message string for this entry. | journalctl MESSAGE='Failed unmounting /var.' | Looks like message has to be the exact message to be matched. No pattern or partial message seems to match. |
PRIORITY | severity or verbosity level, based on syslog priority concept | journalctl PRIORITY=3 | syslog's severity levels |
_COMM _EXE _CMDLINE |
The name, the executable path, and the command line of the process the journal entry originates from. | journalctl _COMM=pulseaudio | |
_SYSTEMD_UNIT | systemd unit name (if any) |
|
Looks pretty similar to -u / --unit, but gives slightly different results |
_TRANSPORT=value | How the entry was received by the journal service. value is one of :
|
+
between terms will combine the one before and the one after into a logical OR
Flag | Usage |
---|---|
--disk-usage | Shows the current disk usage of all journal files : the sum of the disk usage of all archived and active journal files. |
-f --follow | Show only the most recent journal entries, and continuously print new entries as they are appended to the journal (i.e. like tail -f) |
--no-pager | Do not pipe output into a pager
a pager is a utility used to display text, scroll up/down, scroll 1line/1page, search, ..., such as less
|
-o outputOption --output=outputOption |
Controls the formatting of the journal entries that are shown. Among available values : verbose |
-r --reverse | reverse output : newest entries first |
-S 'YYYY-MM-DD hh:mm:ss' --since='YYYY-MM-DD hh:mm:ss' |
Show entries on/newer than the specified timestamp. Missing time will be interpreted as 00:00:00 , missing seconds will be interpreted as :00 |
-u unit --unit=unit | Show messages for the specified systemd unit unit (list available units) |
-U 'YYYY-MM-DD hh:mm:ss' --until='YYYY-MM-DD hh:mm:ss' |
Show entries on/older than the specified timestamp. Missing time will be interpreted as 00:00:00 , missing seconds will be interpreted as :00 |
--vacuum-files=finalNumberOfLogfiles | Remove archived journal files until there remain only finalNumberOfLogfiles logfiles this will leave the active journal files untouched
|
--vacuum-size=finalLogsSize |
|
--vacuum-time=timespan |
|
Just use the → key to view long lines
man journalctl is not very helpful when it comes to wrapping long lines (search wrap and pager for details). To view long lines, you can also :no pager, pleasein the first place, then piping everything into ... a pager .
This construct could prove useful in scripts, however it is not necessary when trying to grep something which is hidden by the default pager :
Considering 2 files :
Joe Dalton Jack Dalton William Dalton Averell Dalton
Joe 23 Jack 22 William 21 Averell 20
join names.txt ages.txt returns :
Joe Dalton 23 Jack Dalton 22 William Dalton 21 Averell Dalton 20