Live data from Hacker News

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

meetryanflowers.com

1–10 of 61 posts

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

#2
I thought this was going to be about modern replacements for `ls` or `more`. Or maybe `ip` vs `ifconfig`.

awk and friends are good tools to process text. Not JSON. A new field, or a format change, will thrash your brittle script contraption. Please use the right tool for each job.

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

#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 caught in a time-travel accident, and if you must parse JSON using classic Unix tools, consider using lex and yacc. They are sufficiently powerful to do the job correctly.)

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

#5
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 would say the same thing about sed and awk. I have a few basics down solid, but anything complex is best done with python.

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

#6
post #2

I thought this was going to be about modern replacements for `ls` or `more`. Or maybe `ip` vs `ifconfig`. awk and friends are good tools to process text. Not JSON. A new field, or a format change, will thrash your brittle script contraption. Please use the right tool for each job.

Yes. Pipe the json through gron or similar first.

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

#7
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…

[deleted]

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

#8
I'm often in the same position, for me it's often quicker to hack something together with what I know than using a new technology.

It's just a matter of experience with the toolchain.

You only have to be cautious when your input is mangled in some way (with escape characters etc) and your toolchain cannot cope with such things.

There are many different versions of cut, awk, sed and even jq. I don't consider this very portable.

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

#9
post #2

I thought this was going to be about modern replacements for `ls` or `more`. Or maybe `ip` vs `ifconfig`. awk and friends are good tools to process text. Not JSON. A new field, or a format change, will thrash your brittle script contraption. Please use the right tool for each job.

[deleted]

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

#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

Post reply on HN