Profile PictureSundeep Agarwal

CLI text processing with GNU sed

1 rating


You are likely to be familiar with using a search and replace dialog (usually invoked with the Ctrl+H shortcut) to locate the occurrences of a particular string and replace it with something else. The sed command is a versatile and feature-rich version for search and replace operations, usable from the command line. An important feature that GUI applications may lack is regular expressions, a mini-programming language to precisely define a matching criteria.

This book heavily leans on examples to present features one by one. In addition to command options, regular expressions will also be discussed in detail.

Exercises are also included to test your understanding.

Promo video


You should be familiar with command line usage in a Unix-like environment. You should also be comfortable with concepts like file redirection and command pipelines. Knowing the basics of the grep command will be handy in understanding the filtering features of sed.

You are also expected to get comfortable with reading manuals, searching online, visiting external links provided for further reading, tinkering with illustrated examples, asking for help when you are stuck and so on. In other words, be proactive and curious instead of just consuming the content passively.

If you are new to the world of the command line, check out my Computing from the Command Line ebook and curated resources on Linux CLI and Shell scripting before starting this book.


Thank you for choosing to write and share your knowledge. I read your books on CLI and sed - I think they are very comprehensive and very well explained. Keep up the great work — feedback on twitter

Sample chapters

For a preview of the book, see sample chapters on GitHub.

GitHub repo

Visit for markdown source, example files, exercise solutions and other details related to the book.

Interactive exercises

Based on the book contents as well as the exercises, I made an interactive TUI app with 50+ questions. Reference solutions are also provided.


  1. Preface
  2. Introduction
  3. In-place file editing
  4. Selective editing
  5. BRE/ERE Regular Expressions
  6. Flags
  7. Shell substitutions
  8. z, s and f command line options
  9. append, change, insert
  10. Adding content from file
  11. Control structures
  12. Processing lines bounded by distinct markers
  13. Gotchas and Tricks
  14. Further Reading

Feedback and Errata

I would highly appreciate it if you'd let me know how you felt about this ebook. It could be anything from a simple thank you, Gumroad rating, pointing out a typo, mistakes in code snippets, which aspects of the book worked for you (or didn't!) and so on. Reader feedback is essential and especially so for self-published authors.

You can reach me via:

Add to cart

You'll get PDF and EPUB versions of the book.

Last Updated
Copy product URL


(1 rating)
5 stars
4 stars
3 stars
2 stars
1 star

CLI text processing with GNU sed

1 rating
Add to cart