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

@rl_dane

Heh, I just got to run grep grep on my shell history.

@amin @rl_dane you guys use flags?... :p

@sotolf @amin

πŸ΄β€β˜ οΈ

@rl_dane @amin

$ Shiver me timbers, comb through this here scroll and fetch me anythin' about pirates, but none o' them feathered devils!

@sotolf @rl_dane

Not usually, but -v is useful to select anything that doesn't match, and -E lets me use extended Regex, which is occasionally useful.

@amin @rl_dane Yeah, it was mostly a joke, I do use -v at some times, but I usually have enough of an idea of what I look for, and am not really doing much complex scripting, so I don't usually need the complex stuff that grep can do :)

@sotolf @amin

grep -vxf file2 file1 is very useful for displaying lines that are in file1 but not file2, like a position/sort-independent diff

-x matches whole lines, and of course -f reads regexps from a file.

@rl_dane @sotolf

I use comm for comparing files.

@amin @sotolf

There are so many little unix utilities I keep forgetting about, like comm. XD

I have used that before. It's nice.

@rl_dane @sotolf

I need to finish my "all the coreutils" blog post…

@amin @rl_dane @sotolf You guys still use grep instead of ripgrep. Tst

@thedoctor @rl_dane @sotolf

I use ripgrep if I want to, say, search a whole codebase.

@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 @amin @sotolf mksh instead of GNU bash, grep/ed/sed/xmlstarlet/jq instead of awk, lynx (and firefox) instead of firefox, and… well I’m still in IRC and occasionally Usenet…

@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

@rl_dane Those are so not comparable!

@amin @sotolf @mirabilos

@thedoctor @rl_dane @amin @mirabilos At least bash and zsh is comparable to grep ripgrep, as zsh is just a strictly better bash ;)
@rl_dane @sotolf @amin @thedoctor strictly even slower 😹
@mirabilos @rl_dane @amin @thedoctor Well, I see you have never tried fish :p
@kabel42 @mirabilos @rl_dane @amin @thedoctor No, it's absolutely not fun, first of all it breaks all scripts. They break all the shortcuts that I use all the time in interactive sessions, it's slow, and if you want to configure it, guess how you configure a command line tool it boots up a web server where you configure it... the whole thing is utterly ridiculous.
@mirabilos @rl_dane @amin @thedoctor @sotolf you probably have some browser installed anyway so why not use it. And you can rewrite all your scripts in a new, more sane, language that is not based on some legacy tech. 
@mirabilos @rl_dane @amin @thedoctor @sotolf extra fun if you install it on a shared server in the lab and make it the default shell.

@kabel42 I see you also like to see the world burn.

@mirabilos @rl_dane @amin @sotolf

@kabel42 @mirabilos @rl_dane @amin @thedoctor On most of the servers that I manage, no I don't have a browser installed, why would I? And fish's language, sane? what you smoking bro? I want some of that as well.
@rl_dane @kabel42 @sotolf @thedoctor @amin I do have lynx, but also the feeling that that isn’t what you are thinking of when you write browser
@rl_dane @sotolf @thedoctor @amin @mirabilos fish, the shell for people that prefer mouse over keyboard 
@rl_dane @thedoctor @kabel42 @sotolf @amin the Korn Shell language is neither legacy nor insane
@kabel42 @sotolf @rl_dane @amin @thedoctor also, I hate how "legacy" and "modern" are fighting words nowadays. Best to avoid them in polite conversation.

@mirabilos @kabel42 @rl_dane @amin @thedoctor

Legacy is mostly the safe route to go anyway, tried and tested, I am the one that gets called if shit stops working, and I'd rather have something I know and makes sense, with tons of resources of administrators of the before times having struggled with them to help me figure out what is going on. Rather than modern stuff, with their ai documentation, discord "forums" and shipping their whole pc (docker) because they couldn't get their shit to work on a clean system :p

@mirabilos @rl_dane @amin @thedoctor @sotolf legacy had old bugs that are well documented and no one dares to fix, modern has, too often, not learned from past mistakes

@mirabilos @thedoctor @kabel42 @sotolf @amin

ksh got started in... 1983? That's not legacy? XD

@rl_dane @mirabilos @thedoctor @sotolf @amin back in the 2. millennium when most computers were lonely and without a connection to the great network. :)
And before the general availability of Advanced CMOS Logic 
@kabel42 @sotolf @rl_dane @thedoctor @amin not in the sense if the word that is commonly used/understood contemporarily, no