1

Hello I need to grep for specific string and I need to print output before/after until a matching word. Here is an example: The string which I search is dmz (I need exact string match because I have similar strings that contain dmz1 which are not in my interest) and I need to print the whole output that start with "edit" until "next"

=============================
edit 1825
set uuid 1e73dff8-2037-51e7-9713-3539a6b60c4c
set srcintf "dmz" <---
set dstintf "tralalala"
set srcaddr tralalala
set dstaddr tralalala
set action accept
set status disable
set schedule "always"
set service "tralalala"
next
===========================

Thanks.

  • Please see this thread. https://unix.stackexchange.com/questions/206903/match-exact-string-using-grep – Mohit Sharma Feb 25 '21 at 08:41
  • Do you mean that all lines between edit and next have to be printed if dmz appears between those lines? Also, what do you mean by "exact string"? In my mind, dmz1 contains the exact string dmz. In your mind, it doesn't seem to. – berndbausch Feb 25 '21 at 10:44
  • Are the lines with the equal signs part of the data? Does the next and previous record contain the equal signs, or are they shared? Does the first record start with the equal signs? Could you show a more complete data set? What should happen if there are multiple records containing the word dmz? What happens if a record contains the word dmz elsewhere and not with a set srcintf at the start of the line (like set service "dmz")? – Kusalananda Feb 25 '21 at 10:47

0 Answers0