Yes, I know
How to use Sed substitutions—from basic to advanced

If you can go beyond the most basic use cases, the sed substitution command will give you a tremendous amount of power to process and transform your text files.

 Get the support materialCheck your mailbox for the link!  View on YouTube 

How to use Sed substitutions—from basic to advanced

In this video, you will see 6 examples of sed substitution commands, from the most basic use case to some more advanced features like capturing groups and back-references.

How can I take the most of this video?

I encourage you to download the files used on the video so you will be able to try the same commands as me on your own system.

The link above will allow you to download a gzipped tar archive of the files used in the video. To extract the content of that archive on your system, you can use the command:

    tar xzf Yes_I_Know_IT-Ep08.tar.gz

In addition, as a reminder, you might want to take a look at my Sed Cheatsheet which summarizes the core sed commands and syntaxes.

What is the target audience?

This video is clearly aimed toward new shell users. The video was designed on a Linux system and using the Bash shell. But the features demonstrated here are generic enough to work with other shells and/or other Unix-like OS (*BSD, MacOSX, …​).

Please notice I use extended regular expression in this video (the -E flag you will see in the sed commands used in this video). It shouldn’t be an issue, unless you running an Unix-like system released in the early 80s. And if you are running such an obsolete system, I really want to hear more about you!

Regular expressions

The video introduces few regular expression patterns to show you how you can leverage them in your sed substitution commands:

  • \b The word boundary matcher

  • . (the dot) Any character

  • \w The "any letter" metacharacter (equivalent to [a-zA-Z0-9_] in the English locale)

  • [a-z] The range matcher

  • (…​) Capturing groups

  • (…​|…​|…​) The alternation

  • \1…​\99 Back references

In addition, I use a couple of very common quantifiers — which are used to search for repeating occurrence of the preceding pattern:

  • …​* Repeat the preceding pattern 0 or more times

  • …​+ Repeat the preceding pattern 1 or more times

A full coverage of regular expressions is out of scope for this video. But if you want more, I encourage you to take a look at the great regex101 online tool to explore and experiment with regular expressions.