3 ms·
Yeah, this just proves to me that the intuitive shell tools are way better. I'll keep all the heads, tails, cuts, and trs, etc.
by jrm4 4y ago
Yeah, this just proves to me that the intuitive shell tools are way better. I'll keep all the heads, tails, cuts, and trs, etc.
- LanternLight83 4y agoI think awk and sed are great, and it's great to eschew pipes when a powerful component that's ready in the pipelibe, like sed, awk, or grep, can pull double duty, but do think that one should favor using `grep -e` with a positive look behind in a case like this. I can just picture an innocuous string being added anywhere above the version string and throwing this one-liner off, when a regex could have pulled the version string out from an arbitrary position within the file and would hold up much more robustly; You don't want to impose opaque constraints on future edits even if you're the only one who will be editing the file, it's just too easy to forget and trip over later.
- jrm4 4y agoI'm whatever the opposite of a code golf extremist is. E.g. I hate the so called "useless use of cat." I uselessly use cat all the dang time; visualizing the pipeline is infinity more useful then, what, "elegance?" Who cares?
- piperswe 4y agoSame here. I use `cat` as a tool to read data from the filesystem into a pipeline, regardless if that's the initial intention of the tool. I don't want the input filename being to the right of the first manipulation command in a pipeline that's supposed to read left to right!
- venil 4y agoIts actually part of the POSIX standard that redirections can be put anywhere in the command line, so one can do: <file.txt sed 's/some/filter' | other_cmd on any standard compliantish shell :) (I use zsh, and I know it also works for bash and dash)
- jrm4 4y agoNever knew this. Looking at it now. First impression, I can't tell if this is idiotic or genius :)
- nmz 4y agoWell, its only intuitive because you already memorized what all the options and command lines do. I for one don't even remember how to use head, I just sed 15q instead of head -n 15, s/// is clearer than a cut sometimes. if you're starting unix, learning sed/awk is enough to do everything.
- jrm4 4y agoAs someone who teaches this stuff, I don't think so? Down the line you can do memorization of quicker ways, but I think "memorization" and "intuition" are opposites here. As in, starting the pipeline with "cat" every time makes intuitive sense more than taking the time to figure out which command to start with?
- nmz 4y agoSure, is egrep a|egrep b| egrep c more intuitive than awk '/a/ && /b/ && /c/'. sure, until you need to have more control over the pipe, in which case, you already forked to awk. so why not go all the way and keep the operation as an awk expression? The great thing about it is, the more you use a tool, the faster you are at using it.