- [Instructor] Welcome to the next video of Section 4,
Removing a Sentence in a File Containing a Word.
In the previous video we have learned how to parse
email addresses and URLs from text.
In this video we learn how to remove a sentence
in a file containing a word.
Removing a sentence containing a word is a simple task,
when a correct regular expression is identified.
This is just an exercise in solving similar problems.
Sed is the best utility for making substitutions.
Hence, let's use sed to replace the matched sentence
with a blank.
Let's create a file with some text
to carry out these substitutions.
For example.
We will remove the sentence containing the words
mobile phones.
Use the following sed expression for this task.
This section assumes that no sentence
spans more than one line.
For example, a sentence should always begin and end
on the same line of the text.
Let's evaluate these sed regexp like this.
It has the format, which is highlighted here.
It replaces every occurrence of
substitution-underscore-pattern with replacement string.
Here the substitution pattern is the regexp for a sentence.
Every sentence is deliminated by dot.
And the first character is a space.
Therefore, we need to match the text in the format
space, some text, match string, some text, dot.
A sentence may contain characters except a dot,
which is the delimiter.
Hence we have used this
and match a combination of any characters except the dot.
In between the text match string, mobile phones is placed.
Every matched sentence is replaced by slash, slash, nothing.
Also we've successfully learned how to remove a sentence
in a file containing a word.
In the next video,
we'll learn how to replace a pattern with text
in all the files in a directory.