Live data from Hacker News

How to Make Money Using Grep, Sed and Awk

openmonstervision.github.io

11–20 of 42 posts

Re: How to Make Money Using Grep, Sed and Awk

#11
post #5

"How to make money by posting a pretty boring article to HN and asking for book purchases at the end of it"

I didn't mind, I actually lolled when reading his other blogpost about how he botched the personal question part of an interview: https://openmonstervision.github.io/blog/posts/how-not-to-ge...

Re: How to Make Money Using Grep, Sed and Awk

#12
post #5

"How to make money by posting a pretty boring article to HN and asking for book purchases at the end of it"

I didn't mind, I actually lolled when reading his other blogpost about how he botched the personal question part of an interview: https://openmonstervision.github.io/blog/posts/how-not-to-ge...

That article /is/ funny.

It also doesn't beg for book purchases for books he didn't write... :P

Re: How to Make Money Using Grep, Sed and Awk

#13

Earlier quoted context omitted.

In my experience it tends to be at around 50 to 100 lines. At this point you usually encounter at least one "gotcha" or difficultly that bash can't handle in an elegant way and realize that it would probably be a lot faster if you just used another language instead.

As soon as I start adding ifs and battling to remember the exact syntax I give up and move to Python and argparse. Recently I've started using the Begins[1] library to make useful command line tools and scripts even more quickly. I appreciate it's less and less portable at this stage but so much more productive. Most of the time these scripts are very specific anyway so it's not a concern. The other thing I've notice…

Begins looks awesome, thanks for sharing! :)

Re: How to Make Money Using Grep, Sed and Awk

#14
post #9

Dude! You need help with using your tools' features to reduce your pipeline lengths. - grep derp | sed whatever is the same as sed '/derp/ whatever' (you might be interested in sed -r for that matter) - sed whatever | sed whatever\ else is the same as sed -e whatever;whatever\ else This list is by no means complete but saves a lot of external processes already, and seriously: think about writing the whole thing in pu…

I disagree, unless it's slow enough to effect performance, I prefer to combine simple pipes.

The only time I have to use more complicated constructions is to get around the stupid problem that passing filenames with pipes is almost impossible to do safely.

Re: How to Make Money Using Grep, Sed and Awk

#15

Earlier quoted context omitted.

In my experience it tends to be at around 50 to 100 lines. At this point you usually encounter at least one "gotcha" or difficultly that bash can't handle in an elegant way and realize that it would probably be a lot faster if you just used another language instead.

As soon as I start adding ifs and battling to remember the exact syntax I give up and move to Python and argparse. Recently I've started using the Begins[1] library to make useful command line tools and scripts even more quickly. I appreciate it's less and less portable at this stage but so much more productive. Most of the time these scripts are very specific anyway so it's not a concern. The other thing I've notice…

Thanks for pointing to Begins!

I suspect some of this is just a difference in background or culture; shell conditionals look completely obvious and intuitive to me, and I'm pretty sure my team can handle shell better than python.

Re: How to Make Money Using Grep, Sed and Awk

#16
post #2

At what point it pays off to switch to python/node instead of keep growing a bash script?

The beauty of bash scripts is that anything with u+x in your PATH, aliases and user-defined functions become a first-class citizen with the same interface. The usual plumbing with pipes and redirection -- and sometimes some more advanced stuff like process substitution -- is often all you need. Moving to Python, say, makes the control flow and the "software engineering" easier, for sure. However, don't underestimate…

There's no reason you can't orchestrate awk and other tools from python though. (I doubt I'm the only one that's done that before).

Re: How to Make Money Using Grep, Sed and Awk

#17
post #9

Dude! You need help with using your tools' features to reduce your pipeline lengths. - grep derp | sed whatever is the same as sed '/derp/ whatever' (you might be interested in sed -r for that matter) - sed whatever | sed whatever\ else is the same as sed -e whatever;whatever\ else This list is by no means complete but saves a lot of external processes already, and seriously: think about writing the whole thing in pu…

I disagree, unless it's slow enough to effect performance, I prefer to combine simple pipes. The only time I have to use more complicated constructions is to get around the stupid problem that passing filenames with pipes is almost impossible to do safely.

there's always find -print0 and many core tools support -z (-0 for xargs). but you have a point of course, YMMV applies.

Re: How to Make Money Using Grep, Sed and Awk

#19
post #2

At what point it pays off to switch to python/node instead of keep growing a bash script?

Long after this particular case. I'd be surprised if it could be done in fewer than twice the lines of code the author used in any language other than Perl (which might make the case for using Perl at around this point, if you like Perl). But, Python and Node would surely be a lot longer.

Shell with awk/sed/grep is very powerful and very composable for small parsing tasks like this. (It could have been done with even less code than this, but I don't blame the author for not figuring out all the necessary incantations to do so, as these tools can be fiddly if you don't use them every day.)

Re: How to Make Money Using Grep, Sed and Awk

#20
post #16

Earlier quoted context omitted.

The beauty of bash scripts is that anything with u+x in your PATH, aliases and user-defined functions become a first-class citizen with the same interface. The usual plumbing with pipes and redirection -- and sometimes some more advanced stuff like process substitution -- is often all you need. Moving to Python, say, makes the control flow and the "software engineering" easier, for sure. However, don't underestimate…

There's no reason you can't orchestrate awk and other tools from python though. (I doubt I'm the only one that's done that before).

No, of course not, but it’s way easier in Bash because of the first-class-ness of commands. In Python, you’d have to mess about with the subprocess module, etc.
Post reply on HN