sed Delete command Delete one line containing a pattern

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Given a file file.txt with the following content:

line 1
line 2
line 3

You can delete a line from file content with the d command.

The pattern to match is surrounded with default / delimiter and the d command follows the pattern:

sed '/line 2/d' file.txt

The above command will output:

line 1
line 3

To edit the file in place, use the -i option:

sed -i '/line 2/d' file.txt


Got any sed Question?