2 ms·
Everyone who's serious about unix should learn a bit of ed. Ed + a here doc is really useful for some types of batch edits that you can't do using sed or perl
by seanhunter 6y ago
Everyone who's serious about unix should learn a bit of ed. Ed + a here doc is really useful for some types of batch edits that you can't do using sed or perl -pi -e. Say you want to delete the line before the second line which starts "---" in the yaml frontmatter of 100 markdown files or swap the second and third line or whatever. Ed is your go-to.
find somedir -name "*.md" | while read f ; do
ed $f <<__DONE
...whatever magic you need
w
__DONE
done
I've done this kind of thing in shellscripts so many times. Recently it was in recovering my personal website by dumping out the wayback machine through lynx and retro-converting the text to markdown.