This seems like it should be easy, but I can't get the right syntax. I'm trying to use grep to find all files with a certain token that have at least one line following the line with the token in it. So something like:
blah blah token blah
another line here
would be found by the grep, but not:
开发者_StackOverflow中文版blah blah token blah
I'm pretty sure grep
doesn't do multi-line stuff like this (though there is a -A option to print trailing context). One way would be to use head
to cut off the last line first, then pipe it to grep
:
for f in *; do
echo "$f:"
head -n -1 "$f" | grep token
Above code is not tested, I'm stuck on Windows atm.
精彩评论