Follow

shout out to the creator of Bash for making me Bash my Fucking Skull Into A Wall every time I read a script

i know I'm a moron with bash, but come ON there has got to be a better way to massage data than grep | awk | sed

hmm jq seems promising, too bad I'm reading command output and not JSON

Is the string a space-delimited array or a newline-delimited array? I don't know, and bash can't give me a straight answer

@eletious Back when I was a log jockey it was all cut, awk and perl one-liners for me. The ones that seemed to have the easiest time with it were the awk hackers; I never got that good at it but I can tell you that it generally takes less awk than perl to do the same thing when it comes to mangling text files

@swaggboi @eletious yep, awk is turning-complete even if it looks like shit. I'm not that good at it, but I'm always amazed at how powerful it is when I do use it.

nushell is pretty wild for working with data/objects instead of text, but might not be helpful for this particular usecase.
nushell.sh/

@eletious can we see a sample of your data, and what exactly you're trying to do with it? (apparently I'm a glutton for punishment)

@zyk @swaggboi sure - I'm aggregating several -p <directory> <size> arguments into an array and attempting to run du -h piped into awk to determine if a directory or file exceeds a size threshold. the trouble arose when i tried to split the du -h output into chunks for processing - using 'for i in `du -h $path`' turns the output into a space-delimited array, but then putting the du output into an array and iterating by index broke things in an even more hilarious way.

Ultimately, after spending some time AFK, I've decided that the approach was kind of dumb and I was too frustrated to actually think about it properly. I don't know how, but at one point in my fussing about I got the du output into an array, but newline-delimited instead of space delimited, and I hadn't touched IFS... at that point it was time to whine on the Internet

@swaggboi i may end up rewriting the script I've been working on entirely - I did look into the awk bits and found that awk is really powerful, though I'm a bit worried about scripting myself into an AWKward position 😏

@eletious @swaggboi I did a little thinking about this last night although I haven't labbed anything yet.
Are you aware du has a --threshold option? It plays nice with human-readable numbers too. There's also an option to NULL separate the output, which will probably simplify your IFS hax

@zyk @swaggboi I ended up using du -k and then using awk to convert the byte size into GB when giving the report - i forgot that du on macos reports in 512-byte blocks

Sign in to participate in the conversation
eattherich.club

are ya hungry? 🦆