You could use awk for that purpose:
awk 'index($0,"vm-1178")>0 {in_pat=1; print; next} \
in_pat == 1 && $0 ~ /^-->/ {print; next} \
{in_pat=0}' logfile.txt
This will look for lines containingIt contains three rules:
- The first rule will look for lines containing the pattern and print these, as well as setting an internal flag
in_patto 1. - The second rule states that all subsequent lines starting with
-->will be printed as well. - The third rule is used to reset that flag upon the very first line not containing the pattern or not starting with a
-->, so that nothing is printed until the pattern is found again.
Note that in the pattern and print these, as well as setting an internal flag in_pattern to 1. All subsequent lines starting with --> will be printed as well. The very first line not containingrule, the pattern or not starting with a -->index will reset the flag, so that nothingfunction is printed until the patternused rather than a RegExp match. This is found againso that you can also look for patterns containing characters that have a special meaning in regular expressions.