jq count the number of items in json by a specific key

Here’s one solution (assuming the input is a stream of valid JSON objects) and that you invoke jq with the -s option: map({ItemId: .Properties.ItmId}) # extract the ItmID values | group_by(.ItemId) # group by “ItemId” | map({ItemId: .[0].ItemId, Count: length}) # store the counts | .[] # convert to a stream A slightly more memory-efficient … Read more

Checking file owner permissions

You can use stat to get the file permissions, and parse them with another command to get the character you want. stat -c %A someFile Returns something like: -rw-rw-r– EDIT: Here you go: stat -c %A someFile | sed ‘s/…\(.\).\+/\1/’ Returns either – or x if the owner has execute. EDIT 2: For completion’s sake: … Read more

Running Bash commands in Java

You start a new process with Runtime.exec(command). Each process has a working directory. This is normally the directory in which the parent process was started, but you can change the directory in which your process is started. I would recommend to use ProcessBuilder ProcessBuilder pb = new ProcessBuilder(“ls”); pb.inheritIO(); pb.directory(new File(“bin”)); pb.start(); If you want … Read more