1. Home
  2. Training Library
  3. Linux Administration Bootcamp Introduction | CSL4 V2 A3.1 |

Strip Out Comments and Blank Lines

Contents

keyboard_tab
Linux Administration Bootcamp
Installing and Connecting to a Linux System
2
Linux Boot Process and System Logging
33
Disk Management in Linux
36
Partitions
PREVIEW6m 50s
38
User Management in Linux
Shell Scripting with Linux
54
55
Start course
Overview
Difficulty
Beginner
Duration
7h 28m
Students
2
Description

In this course, you will learn how to install a Linux system and connect to it, whether that be on Mac or Windows.

Transcript

We can strip out comments and blank lines with a grep command. We'll use the dash capital E option to enable extended regular expressions, V to invert our matches which means only print lines that do not match our search pattern, and we'll use this search pattern. In regular expressions, the carrot symbol represents the beginning of the line. So if we have a line that begins with a pound sign, we're not going to print it since we have the dash V option enabled. The pipe in regular expressions means "or" so if a line begins with comments, don't print it, or if we encounter a blank line, don't print it. And the blank line is represented by carrot again which means the beginning of the line and dollar sign, which represents the opposite, the end of a line. And then you would just specify the file that you're working on to strip out those comments and blank lines.

Let's look at an actual example. So find a configuration file. Well cat httpd.conf and then you can see here at the bottom there are comments. In the middle of the page you can see where there is a blank line. So let's run our command on this file. And then now you can see that it's all the data is compact. No comments, no blank lines. So before the file had 1009 lines in it, but once we strip out the comments and blank lines, it only contains 238 lines that contain real configuration information.

About the Author