7 ms·
I find it massively useful in practice, even for mundane tasks. For example, the other day I was trying to search the columns of a very large SQL Server table¹
by PeCaN 10y ago
I find it massively useful in practice, even for mundane tasks.
For example, the other day I was trying to search the columns of a very large SQL Server table¹ but also needed information about the column type.
…\dbo.site> ls Columns | select Name, DataType, {$_.Properties['Length'].Value} | where {$_.Name -like '*int*'}
Name DataType $_.Properties['Length'].Value
---- -------- -----------------------------
internal_end datetime 8
internal_start datetime 8
interval_code varchar 5
prod_intv_start int 4
prod_intv_stop int 4
working_int decimal 5
Quick, easy. In a *nix shell that would be very tricky.
¹ SQL Server installs a Powershell extension so that you can essentially treat databases like a fancy object filesystem. It's wicked cool actually.
- schoen 10y ago> Quick, easy. In a *nix shell that would be very tricky. You'd probably need to make an explicit SQL query since you wouldn't have the database integration.
- PeCaN 10y agoWell, yeah, but I mean the concept (grepping in tabular data). If, hypothetically, bash had database integration, ls Columns would probably return something like foo varchar 30 NOT NULL bar decimal 8 baz int 4 Which would be a royal PITA to search for anything in—if I were to search for ‘int’ I'd get all int columns and any columns with int in the name…. I could've used an example involving process lists, but I didn't want to trigger PTSD in anyone who's had to grep the output of ‘ps’ for anything non-trivial. (Plus, the database thing was something I actually did a few days ago.)
- stepvhen 10y agoBut thats why there are tools like awk.
- PeCaN 10y agoawk is rather similar in many ways to powershell, actually, but untyped. I agree most of what powershell does you can do with awk, but it's often less pleasant than powershell (in my experience).
- firethief 10y agops aggregates /proc info for human viewing. Why grep the formatted output rather than the source data?
- PeCaN 10y agoMaybe on Linux. OpenBSD doesn't even have procfs, FreeBSD deprecated it, DragonFlyBSD doesn't mount it by default. /proc is a race condition waiting to happen, so I can't really say I recommend using that.
- joshstrange 10y agoHow 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.
- flukus 10y agoPretty much all databases will support "describe tablename" to do exactly that.