text formatting - jq: building a filter for csv output

I have the below JSON file:{"result": [{ "hostid": "12607", "name": "love", "host": "loveyou", "status": "0", "groups": [ { "groupid": "47", "name": "Flower" }, { "groupid": "145", "name": "Sun" } ], "triggers": [ { "triggerid": "211498", "description": "The host is unavailable by ICMP", "status": "0" }, { "triggerid": "211499", "description": "CPU load above {$CPU}% ({ITEM.LASTVALUE})", "status": "0" }, { "triggerid": "211500", "description": "The hos...Read more

text formatting - Two consecutive OPs after pipe or two jq OPs in one run?

I have to extract data from a slightly mis-formatted JSON string, hence I first pass it through sed & awk.What I have is a command like:`sed 's/},/},\n/g' test.json |awk '/"characater"/ { gsub("\"characater\"", "\"char" ++n "\"", $0) } 1'| jq -r '.frames.frame.lps.lp|.characters[]|[.code_ascii,.confidence]|@tsv'` to extract data from a JSON string that can be seen here: {"response":{"container":{"id":"41d6efcb-24d6-490d-8880-762255519b5f","timestamp":"2018-Jul-11 19:51:06.461665"},"id":"00000002-0000-0000-0000-000000000015"},"frames":{"fram...Read more

text formatting - Use `column -t` and replace separator

I use column command to pretty print a table, e.gcolumn -s ':' -t < /etc/passwdIt works but all separator are replaced with spaces, e.g_applepay * 260 260 applepay Account /var/db/applepay /usr/bin/false_hidd * 261 261 HID Service User /var/db/hidd /usr/bin/falseI need something like this_applepay | * | 260 | 260 | applepay Account | /var/db/applepay | /usr/bin/falseAny ideas? I've just read the manual of column and there's no such option...Read more

Impose response formatting as a key value string

Let's suppose I invoke the following command:pwd && ls -l and I would like to receive response in a desired format for example:[CurrentDirectory=[here_result_of_pwd]] [AllDirectoriesInCurrentDirectory= [here_result_of ls -l command]]Is there any other way to impose a desired way of formatting in Unix for this kind of result?...Read more

text formatting - Tool to auto-format shell script

I got some code above which was into a pdf document, wherever I try to post it indentation is terrible, I would like to get it to a proper formatting for debbuging. Here is my code: #!/bin/bash # to measure average power consumed in 30sec with 1sec sampling interval duration=30 interval=1 RAILS=("VDD_IN /sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power0_input" "VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-0040/iio:device0/in_power0_input" "VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power1_input" "VDD_SYS_SOC...Read more

text formatting - How to prettyprint json using jq standalone?

Currently, when I want to pretty-print a json file using jq, I use:cat file.json | grep jq .Yet I would expect for jq to accept a file name as argument without having to fallback on cat.The man page says: jq [options...] filter [files...] ... By default, jq reads a stream of JSON objects (whitespace separated) from stdin. One or more files may be specified, in which case jq will read input from those instead.Yet running:jq file.jsonfails by throwing compile errors that the keys are not defined.How am I supposed to add the file when runni...Read more

text formatting - Split one column into multiple columns with formatted output

I want to print the output of usernames from /etc/passwd into multiple columns. The output from my server is [root@master vdabas]# cat -n /etc/passwd | cut -f1 -d":" 1 root 2 bin 3 daemon 4 adm 5 lp 6 sync 7 shutdown 8 halt 9 mail10 operator11 games12 ftp13 nobody14 systemd-network15 dbus16 polkitd17 sshd18 postfix19 vdabas20 vani21 delhiI want the output to be as below: 1 root 8 halt 15 dbus 2 bin 9 mail 16 polkitd 3 daemon 10 operator 17 sshd 4 adm ...Read more

text formatting - How to display columns in tab separated files nicely?

I have some Tab separated files that consist of a header that are quite unreadable because of the different length of table entries. Essentially, it looks somewhat like c1 c2 c3 c4A 0 1.0231321321213 92BBBBB 12321.00002131 19912132. 0CC 0.0999813221321 0 0Is there a way to make this more readable with columns spaced wider and the columns nice aligned to from readable columns likec1 c2 c3 c4A 0 1.0231321321213 92BBBBB 12321.00002131 199121...Read more

text formatting - Embed ascii diagram in groff?

I have groff file to generate a pdf in the format:.TLArticle title.AUAuthor name.AIPublication title.SH.LPFirst paragraph.PPMore paragraphsI'm then running groff -ms a.ms -T pdf > a.pdf to generate a pdf. I like how groff makes formatting easy but I'm wondering if it would be possible to include an ascii diagram.For example the following: +-------------------------+ +-----------------+ | | | | | Hello | | | | ...Read more

text formatting - Create 'tree' output from list of files

I have a large list of directories and filenames in the formatdrwxr-sr-x hamiltont/hamiltont 0 2015-03-11 23:54 Archive/Directory One/Subdir/-rw-r--r-- hamiltont/hamiltont 21799 2014-01-10 12:52 Archive/Directory One/Subdir/file2.txt-rw-r--r-- hamiltont/hamiltont 21799 2014-01-10 12:52 Archive/Directory One/Subdir/file3.txt-rw-r--r-- hamiltont/hamiltont 21799 2014-01-10 12:52 Archive/Directory One/Subdir Two/somefile.txt-rw-r--r-- hamiltont/hamiltont 21799 2014-01-10 12:52 Archive/Directory Two/Subdir Something/somefile.txt-rw-r--r-- hamiltont/...Read more