What grep command will include the current function name in its output?

前端 未结 9 2120
夕颜
夕颜 2021-01-07 18:08

I run diff with the -p option so the output will include the name of the function where each change occurred. Is there an analogous option for

9条回答
  •  [愿得一人]
    2021-01-07 18:21

    Assuming you are searching for foobar:

    grep -e "^\w.*[(]" -e foobar *.h *.cpp | grep -B 1 foobar
    

    greps for all functions and all foobar, then greps for just foobar and the preceding lines - which will be only foobars and the containing functions.

    tested on cygwin on windows version

提交回复
热议问题