Live data from Hacker News

Modern Linux Tools vs. Unix Classics: Which Would I Choose?

meetryanflowers.com

31–40 of 61 posts

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#33
post #4

I too can never remember jq syntax when I need to. I usually just end up writing a Python script to extract the part of the JSON I need.

> I too can never remember jq syntax when I need to. I usually just end up writing a Python script

Same here! That's why for small things I made pyxargs [1] to use python in the shell. In another thread I also just learned of pyp [2] which I haven't tried yet but looks like it's even better for this use case.

[1] https://github.com/elesiuta/pyxargs

[2] https://github.com/hauntsaninja/pyp

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#35
post #11

The title should read modern GNU tools. Linux is a kernel and supplies nothing useful for command line lovers. Nonetheless, the more modern tools are generally better, faster and more feature rich. I'd pick them over the older versions unless there was a compelling reason not to. Yes, I've used both. For almost forty years now.

Yes, I was a bit confused about this too. Bash (1989) itself is a modern Linux tool. The Unix classic (released between 1973 and 1985 according to the author) would be sh (1979) or perhaps ksh (1983).

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#36
post #3

Parsing JSON using 'cut' and 'awk' and 'sed' sounds like the jankiest thing ever. Sure, maybe you get it working, after much pain. Then someone decides to format your input JSON a bit differently, and everything fails catastrophically. This is the same problem described in the infamous answer "You can't parse [X]HTML with regex": https://stackoverflow.com/questions/1732348/regex-match-open... (Now, if you've been cau…

Raw JSON, absolutely. I usually use jq -C plus indexing into the dict but then sed/awk/grep (rg) do just fine.

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#37
post #25
post #10

Earlier quoted context omitted.

If JQ is too much, see GRON &| Miller gron transforms JSON into discrete assignments to make it easier to grep for what you want https://github.com/tomnomnom/gron Miller is like awk, sed, cut, join, and sort for data formats such as CSV, TSV, JSON, JSON https://github.com/johnkerl/miller

Gron looks interesting, but I wish there was an option for bash output!

The main benefit (indeed the purpose) of gron is that the output is much easier to manipulate into what you need using basic gnu utils, instead of trying to shoehorn it into jq's syntax.

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#38
post #10
post #4

I too can never remember jq syntax when I need to. I usually just end up writing a Python script to extract the part of the JSON I need.

If JQ is too much, see GRON &| Miller gron transforms JSON into discrete assignments to make it easier to grep for what you want https://github.com/tomnomnom/gron Miller is like awk, sed, cut, join, and sort for data formats such as CSV, TSV, JSON, JSON https://github.com/johnkerl/miller

Nushell is also good for this, especially when you need shell capabilities too.

https://www.nushell.sh/

Re: Modern Linux Tools vs. Unix Classics: Which Would I Choose?

#40
The trick here is to get the hell away from JSON quickly. I only ever use jq to turn JSON into text and then use my crusty old tools on that.

If I’m working on my own thing I’ll use a text based format.

Although recently I parsed json out with head, tail and sed. It was numeric data nicely formatted in lines so it was easier to just remove all the semantic structure than actually parse it.

Post reply on HN