I would like to grep a file to find all instances of the text fn1
that don't have the word call
in front of it and print out four lines before and after the matches (even if the surrounding lines have the word call
in them). I tried
grep -A 4 -B 4 '[^call].+fn1'
but it doesn't get any matches (presumably because of the [^call]
). I cannot just use -v and pipe that that to another grep or vice versa because I want to see the surrounding lines of text. I guess I could use -v on call
, pipe that to grep fn1
and then pipe those lines to another instance of grep that matches the whole lines with context but that seems ugly and might be really slow if there are a lot of matches.
This seems like it should be simple, but I'm not sure. Any help?
EDIT:
Sample data
main code
main code
more main code
call fn1(ii, jj)
even more main code
call fn2
still more main code
function fn1
call fn3
fn1 code
more fn1 code
I would like grep to retutn
call fn2
still more main code
function fn1
call fn3
fn1 code
more fn1 code
I want it to show me all the instances where fn1 is used except when it's being called and I don't want to miss other functions that are being called within the context.
[^call]
does not mean everything except the wordcall
. It means any character exceptc
,a
orl
.