Would you like to learn how to delete all comment lines from a file? In this tutorial, we are going to show you how to remove all comment lines from a file on a computer running Linux.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20

Equipment list

Here you can find the list of equipment used to create this tutorial.

This link will also show the software list used to create this tutorial.

Tutorial Linux - Show only uncommented lines

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Show only uncommented lines.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Display only uncommented lines and remove empty lines.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You learned how to show only uncommented lines and remove blank lines from a file on Linux.

Tutorial Linux - Remove comment lines

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Remove comment lines.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Remove comment lines and remove empty lines.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Congratulations! You learned how to remove commented lines and delete blank lines from a file on Linux.