Posts

Showing posts from June, 2022

remove blank lines with grep command

Image
 In this tutorial, How do remove blank lines with grep command. grep command is used to search text and strings in a given file. For example 1 The content grep_command.txt file as below welcome to huuphan.com I'm Huu [server@xxx$] other web site devopsroles.com [server@xxx$] [server@xxx$] test Tip tip The result, welcome to huuphan.com I'm Huu other web site devopsroles.com 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 ^              match start of line [[:space:]]    match whitespace- spaces, tabs, carriage returns, etc. *              previous match (whitespace) may exist from 0 to infinite times $