Another alternative is `ex`, the predecessor to `vi`. It is actually *the* POSIX tool of choice for in-place scripted file editing; it is extraordinarily more flexible than `sed -i` and arguably even more portable than Perl. (If you stay outside of the Windows world, it's *unarguably* more portable than Perl.) There is a relative dearth on this stackexchange of example commands using `ex`, at least compared with the plethora of example commands using `sed`, `awk` and Perl. However, I myself have delved extensively into the [POSIX specs for `ex`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.html) and I've been beating the drum for it ever since. I've written many answers using `ex` both here and on the vi/Vim stackexchange: - [Delete 4 line above and below 5 line after pattern match](https://unix.stackexchange.com/a/257697/135943) - [How to delete everything after a certain pattern or a string in a file?](https://unix.stackexchange.com/a/257520/135943) - [grep all the lines in a file and write line to a file from the pattern matching point](https://unix.stackexchange.com/a/257472/135943) - [How can I replace a character in all the .php files inside a folder on OS X?](https://unix.stackexchange.com/a/256170/135943) - [How to append some line at the end of the file only if it's not there yet?](https://vi.stackexchange.com/a/6248/4676) Further reading: - [Does Ex mode have any practical use?](https://vi.stackexchange.com/a/2692/4676) - [How to edit files non-interactively (e.g. in pipeline)?](https://vi.stackexchange.com/q/788/4676)