How to parse rackspace big data api response using shell scripting


I am trying to find out after a cluster has been provisioned, if it is active and the IP address of the named node using shell scripting. Below is the response of the API output when using the shell commands listed here: <a href="http://docs.rackspace.com/cbd/api/v1.0/cbd-getting-started/content/viewing_Details.html" rel="nofollow">http://docs.rackspace.com/cbd/api/v1.0/cbd-getting-started/content/viewing_Details.html</a>.

+----------+--------------------------------------+ | Property | Value | +----------+--------------------------------------+ | Id | 4820deb2-6212-44f9-b92f-979fe723ffb8 | | Name | foo | | Status | ACTIVE | | Nodes | 3 | | Type | HADOOP_HDP2_1 | | Flavor | hadoop1-7 | +----------+--------------------------------------+


--------------+ | Id | Name | Role | Status | Public IP | Private IP | +--------------------------------------+--------------+----------+--------+----------------+----------------+ | f530a9f1-79a8-4378-bf2a-b7f7e0c2bdd3 | NAMENODE-1 | NAMENODE | ACTIVE | | |

I believe I can do this using some sort of regex or sed/awk. So just to clarify I would like to extract the current status and the public IP

Thank you in advanced


In order to process your data, it might be easier to convert it in a format which is easier to read, for this, use this filter:

sed -e '/^+[-+]*$/d;s/^| //;s/ |$//;s/ | /|/g'

which will convert your first table into

Property|Value Id|4820deb2-6212-44f9-b92f-979fe723ffb8 Name|foo Status|ACTIVE Nodes|3 Type|HADOOP_HDP2_1 Flavor|hadoop1-7

If you wish, you can drop the header by adjusting the filter like this:

sed -e '1,3d;/^+[-+]*$/d;s/^| //;s/ |$//;s/ | /|/g'

You can then combine this with a second filter to process this data further in any way you want:

awk -F'|' '$1 == "Status" {print($2)}"

You can improve the readability and maintainability of your script by wrapping these two steps into functions and combine these functions in your script:

# rackspace_canonize # Canonize output of racksapace report tools rackspace_canonize() { sed -e '1,3d;/^+[-+]*$/d;s/^| //;s/ |$//;s/ | /|/g' } # rackspace_extract_status # Extract the status field rackspace_extract_status() { awk -F'|' '$1 == "Status" {print($2)}' } # rackspace_extract_public_ip # Extract the public IP rackspace_extract_public_ip() { awk -F'|' '{print($5)}' }

Then the following composition gives you the status:

rackspace_canonize | rackspace_extract_status

and the following composition the public IP:

rackspace_canonize | rackspace_extract_public_ip

Note that you can easily add intermediary filters to narrow down the input of the two *extract* functions.


  • How to parse rackspace big data api response using shell scripting
  • jQuery Creating a style element on fly
  • From Hex Value to EBCDIC in DB2 for iSeries
  • JavaScript - Dynamically create SVG and modify for cursor
  • running script stop in the middle
  • Returning TAutoIntfObject instance from TAutoObject
  • How to immediately see Swift errors in AppCode?
  • Toggle CSS values using Javascript
  • Excel 2003 - Display bug with conditional formatting
  • Big Range of separated cells
  • Refresh Bootstrap Treeview programmatically
  • Update resource in CKAN using python
  • setting GOCACHE=“on” put a bunch of files in the on/ directory
  • Why does Excel VBA adds 16ms at random to exection time
  • Accessing an elements within a array of list of arrays in Python 2.x
  • Luhn algorithm in Haskell
  • read the following link [closed]
  • ASP.NET Web API OData: Navigation Links when using Composite Keys
  • JTextPane shows color different from browser of an HTML
  • VBA(?) How to extract filename of images linked and inserted - Word 2013
  • Hide or disable WebView softkeyboard Go/Done/Enter button
  • Create infinite repeatable Observable from array
  • A regex for maximal periodic substrings
  • Can sklearn DecisionTreeClassifier truly work with categorical data?
  • Yii2 Login with database
  • Neo4j: Legacy Indexes and auto index vs new label bases schema indexes
  • How to add learning rate to summaries?
  • d3.js selection conditional rendering
  • Action Pack components in Rails
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • Button click event not firing in jQuery
  • Custom Tabgroup Appcelerator
  • Avoid links criss cross / overlap in d3.js using force layout
  • Where to put my custom functions in Wordpress?
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • EntityFramework adding new object to nested object collection
  • Binding checkboxes to object values in AngularJs