Displaying a file without Commentary lines

Last update on December 28, 2008 07:29 AM by jak58
Published by jak58

Displaying a file without Commentary lines






It may be needed to view a file without displaying the numerous commentary lines attached to it (especially for the configuration files of your OS) and also considering removal of the empty lines.

Grep


Making use of"egrep" (or "grep-E"):


egrep -v '^(#|$)'  /etc/samba/smb.conf

grep -E -v '^(#|$)'  /etc/samba/smb.conf


Lines starting with a hash (#) or the ending symbol dollar($) shall not be displayed.

In this case the delimiter comment is not placed at the start of line but behind (space or tab), but you can change your expression as follows:

grep -E -v '^(#|;|$|[ ]*#)' /etc/samba/smb.conf

Sed


Making use of sed

sed -e '/^[ ]*#/d' -e '/^$/d' /etc/samba/smb.conf


Here it removes firstly, lines begining with a space or a pound sign, then removes all blank lines.

You can improve the expression like:

sed -e '/^[ ]*#/d' -e '/^[ ]*;/d' -e '/^$/d' /etc/samba/smb.conf

Perl


Making use of perl.


Making use of perl will imply,considering the implementation of regex based on the engine used by the utilities.
-.
Using the NFA (Nondeterministic Finite Automation) engine, though slower than DFA (Deterministic Finite Automation) engine,allows you to refine and manage the regex to get a specific result:

perl -ne 'print unless /^\s*[;\$#]|^$/' file_config
Best answers for « Displaying a file without Commentary lines » in :
[Skyblog] Having a title displayed on two lines Show [Skyblog] Having a title displayed on two lines To put an title on your skyblog two lines, follow the steps below: Consider this example: Line 1 Line 2 You simply type this in your article title: [align=center]Line...
Display file as image mode Show Display file as image mode Option 1 Option 2 Option 3 Below is a tips of how to display file image mode: Option 1 First of all, right click on the file containing the images and select Properties. Then select Customize....
The option to display hidden files and folders has disappeared ShowThe option to display hidden files and folders has disappeared Under Windows XP, you may lose the options that allows you to view files and cookies. This is usually due to changes in the register caused by a virus or malicious software on...
[Linux]Managing file attributes on ext2 Show[Linux]Managing file attributes on ext2 Introduction Isattr chattr Attributes List -A -S -a -c -D -d -I -i -j -s -T -t -u -E -X -Z
How to read a file line by line ShowHow to read a file line by line Intro Tips Bonus Intro One of the most common errors of learning scripts bash on GNU / Linux is to read a file line by line, is to use a loop "for" (for line in $ (cat file.txt) do. ..), which in this...
Download GNU Octave ShowGNU Octave is a program meant for numerical computations and will allow the user to display a command line interface to be able to solve numerical issues that are either linear of nonlinear. Features: The software has add ons that can allow you...
Linux - Tree structure of files ShowFile hierarchy under Linux To ensury compatibility and portability, Linux systems comply with the sole FHS (File Hierarchy Standard) standard. The basic hierarchy is as follows: /the root, containing the main directories /bincontains...
Linux - User management ShowFirst step for the administrator When several people have access to a system, the administrator must manage the users. To do so, he must know the common commands and files to be configured. The important files are: the /etc/passwd file the...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...