Showing posts from June, 2022

Removing Blank Lines Using the Grep Command

In this tutorial, we'll explore how to utilize the grep command to eliminate blank lines. The grep command proves invaluable for searching text and strings within files, providing efficient ways to manage content. Learn the process of removing unwanted blank lines with ease and precision. For example 1 The content grep_command.txt file is as follows: welcome to I'm Huu [server@xxx$] other web site [server@xxx$] [server@xxx$] test Tip tip The result, welcome to I'm Huu other web site Tip tip Use command below: grep -v "\$[[:space:]]*" grep_command.txt The output terminal as below: For example 2 The content grep_command2.txt file as below phan van huu The result, phan van huu Use command as below: grep -v "^[[:space:]]*$" grep_command2.txt # or grep -v "^$" grep_command2.txt The output terminal as below: Explained The -v makes it print lines that do not completely match ^              matc