From the course: Bash Patterns and Regular Expressions

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using sed

Using sed - Bash Tutorial

From the course: Bash Patterns and Regular Expressions

Start my 1-month free trial

Using sed

- [Instructor] Sed is a stream editor, meaning it will edit text as the text is piped through it. By default, it use BREs, but if passed to dash R or dash capital E option, it can use EREs. Sed has a lot of functionality that's beyond the scope of this chapter, so I'll be doing a quick introduction and then showing how to use Regexes with sed. Sed has different modes. The modes we're interested in are print, delete, and substitute. When you print a line that matches a pattern, it essentially operates like grep. The syntax for printing a line with a BRE is sed space dash N, space single quote, slash the BRE pattern, slash P for print, single quote. And for EREs, you would just add a dash capital E option. Sed by default prints all process output, so we need to add the dash N to suppress this. You can put any pattern in here including globs, character sets, character classes, or Regexes does not have to be a Regex. Notice that I didn't specify a file name. We have two choices for…

Contents