4 ms·
sed, and also awk, and ed, are worth learning. I mean coding a chess game in those tools is just a novelty, but you can do so much really useful text processin
by ams6110 13y ago
sed, and also awk, and ed, are worth learning. I mean coding a chess game in those tools is just a novelty, but you can do so much really useful text processing with just those tools, and they are pretty much guaranteed to be available on almost any *nix machine.
- foobarbazqux 13y agoWhat's an example of something non-interactive that ed is good for that you can't easily do with other tools?
- gwu78 13y agoOK I'll bite. For this answer I'll assume "easily" to mean "with less typing". ed has a more concise syntax for joining arbitrary lines of a file (by line number or pattern) and then saving the file (by way of a temp file in $TMPDIR). You could do this with awk and perhaps with other standard tools (note: I don't consider perl to be "standard"). But I think it's safe to say the ed script would always be shorter. ed's syntax for deleting and moving arbitrary lines is similarly concise. For these specific tasks, it's not going to be easy to win at code golf using awk or other tools... and in some cases it may be impossible.
- foobarbazqux 13y agoHey cool, thanks. I've always overlooked it.
- dmlorenzetti 13y agoI use sed in makefiles, to scrape the source code for a version number, and then embed that version number in the name of the executable to be built. That would be easy enough in, say, Python, but as a sed script it's lightweight, decently readable, and puts everything you need to know right there in the makefile. That said, I've recommended learning Python to a few people, but have never even suggested anybody learn sed or awk.
- foobarbazqux 13y agoOh, yeah, sed and awk are great, I meant ed in particular.
- techtalsky 13y agoThat's true... but I haven't had to do real work on a system that didn't already have Python installed on it in a long time.
- paraiuspau 13y agonovelty yes, but let's not detract from the man's prowess; writing a chess game in sed is entirely non-trivial.