当前位置: 动力学知识库 > 问答 > 编程问答 >

newline - Is \n not considered to be whitespace in grep?

问题描述:

I am using grep to find out all occurences of a VB function call. I give the command this way -

 grep -n "FunctionX" FormX.frm

1814: FunctionX

2682: FunctionX

3020:' FunctionX

3292:Private Sub FunctionX()

3333:On Error GoTo FunctionX_Err

3388: ' GoTo FunctionX_Exit

3394:GoTo FunctionX_Exit

3456:FunctionX_Err:

3460:FunctionX_Exit:

But as you can see, it also gave me instances where it was not a function call. For a VB function call, the function name is not followed by anything, so I assumed that it's a function call followed by whitespace. I tried -

 grep -nr "FunctionX[[:space:]]" FormX.frm

However, this gave me no results. Is this because "\n" is not considered to be whitespace? Every call to FunctionX in the code is followed by a "\n". If so, how do I get the desired result? Please help me out. Thanks.

网友答案:

Try matching on the end of line

 grep -nr 'FunctionX[[:space:]]*$' FormX.frm

Remember grep is looking at the input line-by-line, so it's not going to be seeing the carriage returns. The pattern above finds any line that ends with FunctionX with some possible (real) whitespace following it before the end-of-line.

分享给朋友:
您可能感兴趣的文章:
随机阅读: