3 ms·
How would that be hard in a *nix shell? mysql > SELECT column_name, data_type, numeric_precision FROM information_schema.columns WHERE table_schema = ? AN
by joshstrange 10y ago
How would that be hard in a *nix shell?
mysql > SELECT column_name, data_type, numeric_precision FROM information_schema.columns WHERE table_schema = ? AND table_name = ? AND column_name LIKE "%int%"
- emodendroket 10y agoImagine for a second that the DB can't do it and you need to filter the STDOUT output.
- dangerlibrary 10y agoOkay, I've imagined it. It does seem terrible. Fortunately, that's not a world any of us live in.
- emodendroket 10y agoOK, but now imagine it's not a database, because there are programs that do act this way.
- qwertyuiop924 10y agoAnd those programs usually emit proper CSV. You could use regex to match on what you want, but AWK was literally built for this. It's fantastic, it works great, and if you don't use that tool that was built to solve your problem, that's your own lookout.
- emodendroket 10y agoI don't think awk is actually capable of parsing CSVs in all cases.
- qwertyuiop924 10y agoIt doesn't parse escapes, IIRC, but those are rarely emitted.
- PeCaN 10y agoEr, it's a world all of us live in. Say, for example, ‘ps’ or ‘ls -1l’. Then you end up using awk, which is rather like a half-assed version of powershell to work around shortcomings with the unix everything-is-a-string design.
- dangerlibrary 10y agoParent comment was talking about parsing the raw output from a database in stdout. That's what I was responding to, and I'm not wrong.
- qwertyuiop924 10y agoAWK isn't a workaround. It's a tool for processing tabular data, in a textual format. The fact that it can solve so many problems is actually a strength of the EIAS design.
- qwertyuiop924 10y agoThat doesn't sound hard at all. AWK, anyone?
- emodendroket 10y agoWriting awk to do it is definitely more work than calling obj.Property though.
- qwertyuiop924 10y ago$mysql_cmd|awk -F\| '$2 == "what you want the second row to match" {print $0}' Not that much more work. And you can do better if you can coax mysql to emit proper DSV.
- emodendroket 10y agoThat kind of stuff adds up fast in an interactive shell.
- qwertyuiop924 10y ago...Which is why you write a script to do it if it comes up often. Extendable tooling!
- PeCaN 10y agoThe reason I chose that particular example was not for the database integration (which is very cool) but for the fact that it's actually something I did. Point is, imagine trying to grep anything tabular in bash. Hypothetically, the output of ls -la for files with execute permission that have been modified in the last day. Or, more realistically, anything involving ps.
- daveloyall 10y agoImagine trying? Sir/Ma'am, I have done so. When boxed in-between the fearsome foursome--`bash`, `sed`, `awk`, and `emacs`--every problem involving tabular data (2D) is trivial. Hm, I'll give a shout-out to `sort` and `uniq`, too! When you go 3D, you might need to bring in `join`. But anyway, you'd use find ~/bin /usr/bin -mtime 1 -executable -type f -ls ..to provide `ls -la` output for every executable, ordinary files (not directories, which are often +x) modified in the last 24 hours, under the directories /usr/bin or the bin/ under your home directory. :)
- qwertyuiop924 10y agoHey, don't forget cut and xargs!
- daveloyall 10y ago*gulp* I've heard people say that, but I haven't delved into them!! :-S
- qwertyuiop924 10y agocut doesn't match awk, but it's handy for the little stuff. And xargs is the most usefull thing ever.
- grkvlt 10y agoAnd paste for tasks requiring the opposite of cut, then there's tr, the lightweight sed. And jq for structured queries on JSON. But, all these are built in to poweshell, essentially.