File this under #shell #functions I should have written years ago:

function grepc { #Do a grep -c, but skipping files with no results grep -c "$@" |grep -v ':0$' }

#unix #UnixShell #ShellScripting #bash #ksh

@rl_dane

Oh, didn't know about -c. I usually just pipe to wc -l I guess.

@amin

-c, -l, -h, -H, and -q are my favorite #grep flags. :D

Huh, that almost became a [Marcel Duchamp] reference. 😅

Marcel Duchamp - Wikipedia

@rl_dane

I just use -v and -E

@amin @rl_dane you guys use flags?... :p
@amin @rl_dane @sotolf You guys still use grep instead of ripgrep. Tst

@thedoctor @amin @sotolf

...and bash instead of zsh
...and grep/awk/sed instead of jq
...and firefox instead of chrome
...and the fediverse instead of facebook

Face it... I'm an unpopular-opinion neckbeard level boss. XD

cc: @mirabilos

@rl_dane @thedoctor @sotolf @mirabilos

...and grep/awk/sed instead of jq

Okay, now that one is crazy.

@thedoctor @amin @sotolf @mirabilos

LISTEN, I've used grep/awk/sed for very nearly a quarter century, and I find the syntax of jq bewildering, so 😝

@rl_dane @thedoctor @sotolf @mirabilos

Most of those aren't for handling complex data types, though, just manipulating lines.

@amin @thedoctor @sotolf @mirabilos

So far, I've managed to bodge it together just well enough to do what I needed, but I really would like to get more familiar with jq.

@amin @rl_dane @thedoctor @sotolf jq is absolutely bewildering, especially the insistence on filtering (splitting the input stream is so hard and counter-intuitive), but it’s an ok tool if you have JSON. Or YAML, which I [convert (user=pass public)] to JSON anywwy.

xmlstarlet is lovely!

@mirabilos @amin @thedoctor @sotolf

Is it possible to convert JSON to XML and then use xmlstarlet? 😄

XEP-0239: Binary XMPP

@kabel42 @rl_dane @amin @thedoctor @sotolf … yes, but not in a meaningful way.

@kabel42 @mirabilos @amin @thedoctor @sotolf

Sufficiently evil. XD

I remember when XML was the buzzword back in the late naughties.

@rl_dane @kabel42 @sotolf @thedoctor @amin XML is underrated, and Google hates it

@mirabilos @kabel42 @sotolf @thedoctor @amin

Well, if Google hates it, I'm probably on board by default. XD

@rl_dane @amin @thedoctor @sotolf yes, but you’ll have to find out a schema you want to use.

Of course, you could just convert…

{ "foo": ["bar", "baz"], "bar": true }

… to…

<JSONObject> <element name="foo"><JSONArray> <element><JSONString>bar</JSONString></element> <element><JSONString>baz</JSONString></element> </JSONArray></element> <element name="bar"><JSONBoolean>true</JSONBoolean></element> </JSONObject>

… or worse (Apple “plist”), but I suspect you’d rather have something semantically correct.

A lazy way to do this is with [iXML] (“invisible XML”, via @linguacelta of “AIn’t” fame); note you’ll most likely want the draft spec, not the release, because the latter misses a way to specify an XML alias and just uses the grammar name, which must be unique, for the XML element name (so the above mapping, which has object elements and array elements, would not be possible with the 1.0 spec).

That being said, if you do want such a systematic mapping, I could write you a little jq script to do that.

Do note that U+0000 (ouch! I wish it weren’t), U+0001‥U+0008, U+000B‥U+000C, U+000E‥U+001F, U+FFFE‥U+FFFF (ouch²!) are valid in JSON but not XML (and (X)HTML forbids further codepoints). xmlstarlet will likely refuse a document in which these occur (and no, even writing them as numeric entities like &#1; is not permitted).

Invisible XML

@rl_dane @mirabilos @thedoctor @sotolf

I do not feel up to subjecting my notifications to a revival of this thread right now. Bye y'all. :)

@rl_dane @mirabilos @amin @thedoctor conversion is always a dangerous step