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 pure bash or awk. There might be just too little gain to justify including all these tools without composing the many features they provide.
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 some reason for not to write "the perfect" command. Either being in a hurry or you just don't care about it.
Considering the commented out valid code, it looks like he was saving time by just adding another "|" and check the output, instead of improving the existing command and check the output. Something that I do very often as well.
I gave up with all of them. A friend of mine is using Upwork and Freelancer (awful) to find gigs, and he tried to get me involved so I could help him out with overspill. It seemed like you had to put ludicrously low rates to get terrible work, and despite paying peanuts, everyone expects amazing results.
I ditched it, joined some communities online, did a tiny bit of networking, and announced I was looking for work related to X - that was far more fruitful than sending 10 pitches a day for gigs on those sites and getting nothing in response because someone in India will do it for a dollar. Although I did love seeing the same projects re-appear a week later to fix the crap that their offshore team delivered.
Haven't worked below 60$/ for fun things and 80$/h for boring things on Upwork without much reputation. Sure I could find a better paid job, but if you can sell yourself as skilled you don't have to be afraid of the averagely low numbers on there
Actually, it was a project, I priced out at $100. Thinking I could rip through it easily. It took me longer than I thought I am sad to admit, even with my rough pipes, and multiple sed and greppings :)
edit: And the catalog was 1048 pages long not counting the index.
A man who eschews Perl, and all later and more usable tools, in favour of a bastard hodgepodge of shell and awk with a smattering of sed: It's like looking in the mirror.
At what point should one switch from an interpreted to a compiled language?
There probably aren't any hard and fast answers. Take Dracut [1], for example. It's a successful utility completely written as a collection of bash scripts. The answer probably depends on the specifics of your needs and specific benchmarks.
Bash gets a lot of hate, but if you take the time to really learn it as a language and use good coding practices---like linting, verbose warnings, and unit testing---then it's not too difficult to write long bash scripts well. I don't think it's really much trickier or dirtier than JavaScript.
One thing that helps is putting the spiritual equivalent of "use strict" at the top of your Bash script:
shopt -s -o errexit pipefail nounset noclobber
Take a look at `help set` for info on what those settings do. Here's a list of resources that have helped me feel confident when writing bash:
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 the power of grep, sed and especially awk. I wouldn't want to reimplement a half-arsed, presumably non-bug-free version of awk in Python when I could have just used awk in the first place.
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.
Quite a bit after the point where it pays to convert sed and awk one-liners into Perl one-liners and build a program around it.
Perl may be as dead as sed and awk are now, but that was the initial use case for Perl before CGI (as in Common Gateway Interface - the first primitive interface for web apps) came along.
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.)
The best way to make money with grep/sed/awk is to become sufficiently l33t in them, you can be gainfully employed by others to "do things" on "the goddam unixes"
hey.. we got more unixes here. can somebody grep them out the way?
[+] [-] nrki|8 years ago|reply
[+] [-] janvdberg|8 years ago|reply
[+] [-] mar77i|8 years ago|reply
- 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 pure bash or awk. There might be just too little gain to justify including all these tools without composing the many features they provide.
[+] [-] CJefferson|8 years ago|reply
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.
[+] [-] drinchev|8 years ago|reply
Considering the commented out valid code, it looks like he was saving time by just adding another "|" and check the output, instead of improving the existing command and check the output. Something that I do very often as well.
[+] [-] yomansat|8 years ago|reply
A question to those who do freelance work: sites like Upwork often have low budgets, where do you guys find better projects with better compensation?
[+] [-] iDemonix|8 years ago|reply
I ditched it, joined some communities online, did a tiny bit of networking, and announced I was looking for work related to X - that was far more fruitful than sending 10 pitches a day for gigs on those sites and getting nothing in response because someone in India will do it for a dollar. Although I did love seeing the same projects re-appear a week later to fix the crap that their offshore team delivered.
[+] [-] herbst|8 years ago|reply
[+] [-] bsdpunk|8 years ago|reply
edit: And the catalog was 1048 pages long not counting the index.
[+] [-] tragomaskhalos|8 years ago|reply
[+] [-] angarg12|8 years ago|reply
[+] [-] xelxebar|8 years ago|reply
There probably aren't any hard and fast answers. Take Dracut [1], for example. It's a successful utility completely written as a collection of bash scripts. The answer probably depends on the specifics of your needs and specific benchmarks.
Bash gets a lot of hate, but if you take the time to really learn it as a language and use good coding practices---like linting, verbose warnings, and unit testing---then it's not too difficult to write long bash scripts well. I don't think it's really much trickier or dirtier than JavaScript.
One thing that helps is putting the spiritual equivalent of "use strict" at the top of your Bash script:
Take a look at `help set` for info on what those settings do. Here's a list of resources that have helped me feel confident when writing bash: Also, this blog post gives some advice that I found useful: [1] https://dracut.wiki.kernel.org/index.php/Main_Page[2] http://wiki.bash-hackers.org/
[3] https://www.shellcheck.net/
[4] http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.htm...
[5] https://dev.to/thiht/shell-scripts-matter
[+] [-] Xophmeister|8 years ago|reply
Moving to Python, say, makes the control flow and the "software engineering" easier, for sure. However, don't underestimate the power of grep, sed and especially awk. I wouldn't want to reimplement a half-arsed, presumably non-bug-free version of awk in Python when I could have just used awk in the first place.
[+] [-] saagarjha|8 years ago|reply
[+] [-] sqrt17|8 years ago|reply
Perl may be as dead as sed and awk are now, but that was the initial use case for Perl before CGI (as in Common Gateway Interface - the first primitive interface for web apps) came along.
[+] [-] SwellJoe|8 years ago|reply
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.)
[+] [-] unknown|8 years ago|reply
[deleted]
[+] [-] viraptor|8 years ago|reply
[+] [-] tonyedgecombe|8 years ago|reply
[+] [-] ggm|8 years ago|reply
hey.. we got more unixes here. can somebody grep them out the way?
[+] [-] zero_one_one|8 years ago|reply
As you say, the way to make money (with any tool) is to get good enough at using them to be useful to someone that wants to pay you to do so
[+] [-] bsdpunk|8 years ago|reply
[+] [-] nunez|8 years ago|reply
[+] [-] bsdpunk|8 years ago|reply