3 ms·
What's an example of something non-interactive that ed is good for that you can't easily do with other tools?
by foobarbazqux 13y ago
What'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.