Skip to content
Advertisement

Bash script how to display matched words in custom order

The following is the output of the command ads2 cls create

JavaScript

However, I’m trying to extract the value of name and state for each node, save them in a variable and display them in the following order:

JavaScript

Till now i, with the help of this so much powerful learning site, could extract the values of name and state by executing the following:

JavaScript

Now if i print cls variable, i get the following:

JavaScript

First Question:

How can i display the result like the one above in the **#example output**?

Second question

With this implementation, how can I check the value of state varaiable for both nodes in order to print something like

JavaScript

Advertisement

Answer

Since the output seems to be json, you should really use a json parser such as jq but in the absence of jq you can use awk and combine the requirements for question one and two:

JavaScript

Explanation:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement