2017年8月26日 星期六

[Linux 常見問題] How to print a file, excluding comments and blank lines, using grep/sed?

Source From Here 
Question 
As title with text file as below: 
- test.txt 
  1. This is line1  
  2. # This is the line being commented  
  3.   
  4. This is line2  
The expected output is: 
This is line1
This is line2

How-To 
Try command egrep or grep with argument '-E': 
// -E: Interpret PATTERN as an extended regular expression
// -v, --invert-match: Invert the sense of matching, to select non-matching lines.

# grep -E -v '^$|^\s*#' test.txt
This is line1
This is line2


# egrep -v '^$|^\s*#' test.txt
This is line1
This is line2

沒有留言:

張貼留言

[ Python 文章收集 ] SQLAlchemy quick start with PostgreSQL

Source From   Here   Preface   This is a quick tutorial for getting started with   SQLAlchemy Core API .   Prerequisites   In this quick st...