Linux sed command (string editor) [Basic Guide]

The sed command on Linux is a powerful string editor for filtering or editing text strings.

The most common options are:

  • -e: Adds a script to the commands to be executed;
  • -f file: Adds the content of a file as a script to be executed;
  • -r: Uses regular expressions in the script.

Examples:

To replace expressions with others, we use the “s”, with the “/” delimiters, so that the first occurrence is the text to search for, and the second the text that will be replaced. Note that sed will only exchange the first occurrence of each line, and is case-sensitive. The default output of sed will be the terminal.

$ cat file It 
will be hot at night today. The Night is beautiful.
$ sed s/night/day/ file
Today will be hot during the day. The Night is beautiful.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?