You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A while back I wrote an article on my blog on ways to use jc and jq instead of sed, awk, grep, etc. to extract the data you want from command output. I thought I would post those same examples of filtering the JSON converted data from the rpm command using jello this time.
$ rpm -qia | jc --rpm-qi | jello 'sorted([p for p in _ if p.license == "MIT"], key=lambda x: x.build_epoch)[-1]["name"]'"jc"
Oh look - it's jc! We could also do it this way using the operator module:
$ rpm -qia | jc --rpm-qi | jello '\import operatorsorted([p for p in _ if p.license == "MIT"], key=operator.attrgetter("build_epoch"))[-1]["name"]'"jc"
Finally, we can do it with a good old-fashioned loop:
As you can see, there is more than one way to skin a cat in jello using the Python interpreter. That's it for this post. I'll add more examples in another. Do you have other ways to solve this problem in jello?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
A while back I wrote an article on my blog on ways to use
jc
andjq
instead ofsed
,awk
,grep
, etc. to extract the data you want from command output. I thought I would post those same examples of filtering the JSON converted data from therpm
command usingjello
this time.List the package objects that use the MIT license
Here is the method in
jq
:And here is how you can do the same thing in
jello
:As you can see, we can use a simple list comprehension to get the same result.
Grab the name of the latest MIT licensed package
To grab the newest MIT licensed package installed we can use the following
jq
filter:And here's how you do it in
jello
:Oh look - it's
jc
! We could also do it this way using theoperator
module:Finally, we can do it with a good old-fashioned loop:
As you can see, there is more than one way to skin a cat in
jello
using the Python interpreter. That's it for this post. I'll add more examples in another. Do you have other ways to solve this problem injello
?Beta Was this translation helpful? Give feedback.
All reactions