The grep, egrep, sed and awk are the most common Linux command line tools for parsing files. From the following article you’ll learn how to match multiple patterns with the OR, AND, NOT operators, using grep, egrep, sed and awk commands from the Linux command line. I’ll show the examples of how to find the […]
text-processing
Using SED and AWK to Print Lines Between Two Patterns
From the following article, you’ll learn how to print lines between two patterns in bash. I’ll show how to to extract and print strings between two patterns using sed and awk commands. I’ve created a file with the following text. It’ll be used in the examples below, to print text between strings with patterns. I […]
HowTo: View a Config File Without Comments
With the help of ‘grep’ command it is quite easy just to look at the active setting of configuration files, omitting comments. The following command will display the content of the file ‘somefile.conf’, omitting blank lines and the lines started with “#”: $ grep ^[^#] somefile.conf Also, you can pipe the output to a new […]
HowTo: Remove Blank Lines From a File
Use one of the following commands to remove blank lines from a file. 1. Using the grep command: $ grep -v “^$” file.txt 2. Using the sed command: $ sed ‘/^$/d’ file.txt 3. Using the awk command: $ awk ‘/./’ file.txt 4. Using the tr command: $ tr -s ‘\n’ < file.txt You also can […]