'How to find value from arrays of object in shell script?
I have array of objects as given .
array = [{Name:'firstName', value: 'name'},
{Name:'lastName', value: 'lname'},
{Name:'brithDate', value: '1-1-2000'},
{Name:'age', value: 21},]
How can I get the value of age from the array without for loop? In for loop, it takes time and I want it to run in less time because I need to run this for thousands of data. Anyone has solution for it?
Solution 1:[1]
Here's a solution that first uses sed and hjson to convert the text to JSON:
sed '1s/array =//' array.js |
hjson -j | jq '.[] | select(.Name=="age").value'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | peak |
