Fun with terminal plotting JSON data at the command line
One of the great thing about unix is the ability to pipe multiple programs together to manipulate data. Plain, unstructured text is the most common type of data that is passed between programs, but these days JSON is becoming more popular.
I thought it would be fun to pipe together some command line JSON tools to do some stupid terminal tricks, like plotting a graph of system statistics, like CPU or memory utilization.
We can use jc (disclosure: I wrote jc), jq, and jp to pull the output of uptime and display a line graph like this:
In this post I'll show you how you can build a quick bar graph of the CPU utilization of the top processes right in the terminal. For more information on how to create the animated line graph above, see my blog post at blog.kellybrazil.com.
first, get jc, jq, and jp.
Then you can use this one-liner to graph the output of ps:
Fun stuff! jq is an awesome JSON tool for the cli and is a bit like sed or awk for JSON. You'll find lots of uses for manipulating JSON as more and more programs start to output in the format.
Last edited by kbrazil; 01-16-2020 at 04:39 PM..
These 2 Users Gave Thanks to kbrazil For This Post:
Hai Friends
I have installed FreeBSD in my system... I have installed it to work in text mode don't have the GUI. The default text color is Black background with White Foreground. I want it to be with Black background with Green Foreground. How could i do that.
Thanks in advance
Collins (4 Replies)
I have a simple gnuplot question. I have a set of points (list of x,y,z values; irregularly spaced, i.e. no grid) that I want to plot. I want the plot to look like this:
- map view (no 3D view)
- color of each point should depend on z-value.
- I want to define my own color scale
- plot should... (1 Reply)
I have a set of data that looks similar to the following in UNIX:
0.12_0.008_fall_ff.out:bisect return: 0.08056640625
0.12_0.04_fall_ff.out:bisect return: 0.07470703125
0.12_0.12_fall_ff.out:bisect return: 0.06298828125
0.12_0.24_fall_ff.out:bisect return: 0.05126953125
Previously I have... (4 Replies)
I have attached a txt file, what I would like to be able to do is:
1. Extract Data from Columns labeled E/N and Ko into a new file
2. Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis.
3. Lastly I would like to be able to extract multiple data sets and... (6 Replies)
Hello,
I am trying to learn how to pass something more than a one-command startup for gnome-terminal.
I will give an example of what I'm trying to do here:
#! /bin/bash
#
#TODO write this for gnome and xterm
USAGE="
______________________________________________
${0##*/}
run... (0 Replies)
Hi All,
I work on a Linux platform which runs Red Hat (forget which version) and use both korn and bash shells. Is there a way of making the command line appear at the top of the terminal window and any lists, commands or directory names etc to appear below the top, that is to say reverse the... (1 Reply)
Dear All,
Anyone knows how to start a new bash terminal from command line?
Another question: when I use "open" command (open test.pdf) to open a pdf file, the PDF reader will start up, but cannot associate with that file. Anyone knows why? (1 Reply)
Hi guys and gals...
After much searching on the good ol' internet I could find nothing, so this is the result.
ALthough many people seem to have asked this question no-one seems to have a solution so here we go.
I need for AudioScope.sh, 'xterm' to run a second program for some of its... (2 Replies)
Hi Gurus,
I have below JSON file, now I want to rewrite this file into a new file.
I will appreciate if anyone can help me to provide the solution...I can't use jq.
{
"_id": "3ad893cb4cf1560add7b4caffd4b6126",
"_rev": "1-1f0ce165e1d210319cf6e9f9c6ff654f",
"name":... (4 Replies)
Discussion started by: manas_ranjan
4 Replies
LEARN ABOUT DEBIAN
test::json
Test::JSON(3pm) User Contributed Perl Documentation Test::JSON(3pm)NAME
Test::JSON - Test JSON data
VERSION
Version 0.11
SYNOPSIS
use Test::JSON;
is_valid_json $json, '... json is well formed';
is_json $json, $expected_json, '... and it matches what we expected';
EXPORT
o is_valid_json
o is_json
DESCRIPTION
JavaScript Object Notation (JSON) is a lightweight data interchange format. Test::JSON makes it easy to verify that you have built valid
JSON and that it matches your expected output.
See <http://www.json.org/> for more information.
TESTS
is_valid_json
is_valid_json $json, '... json is well formed';
Test passes if the string passed is valid JSON.
is_json
is_json $json, $expected_json, '... and it matches what we expected';
Test passes if the two JSON strings are valid JSON and evaluate to the same data structure.
Test::Differences is used to provide easy diagnostics of why the JSON structures did not match. For example:
Failed test '... and identical JSON should match'
in t/10testjson.t at line 14.
+----+---------------------------+---------------------------+
| Elt|Got |Expected |
+----+---------------------------+---------------------------+
| 0|{ |{ |
| 1| bool => '1', | bool => '1', |
| 2| description => bless( { | description => bless( { |
| 3| value => undef | value => undef |
| 4| }, 'JSON::NotString' ), | }, 'JSON::NotString' ), |
| 5| id => '1', | id => '1', |
* 6| name => 'foo' | name => 'fo' *
| 7|} |} |
+----+---------------------------+---------------------------+
AUTHOR
Curtis "Ovid" Poe, "<ovid@cpan.org>"
BUGS
Please report any bugs or feature requests to "bug-test-json@rt.cpan.org", or through the web interface at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-JSON>. I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
SEE ALSO
This test module uses JSON::Any and Test::Differences.
ACKNOWLEDGEMENTS
The development of this module was sponsored by Kineticode, <http://www.kineticode.com/>, the leading provider of services for the
Bricolage content management system, <http://www.bricolage.cc/>.
Thanks to Makamaka Hannyaharamitu "makamaka@cpan.org" for a patch to make this work with JSON 2.0.
Thanks to Stevan Little for suggesting a switch to JSON::Any. This makes it easier for this module to work with whatever JSON module you
have installed.
COPYRIGHT & LICENSE
Copyright 2005-2007 Curtis "Ovid" Poe, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.10.1 2009-08-09 Test::JSON(3pm)