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

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...