0

I'm trying to grep a html file.

Search text:

Ready to be merged automatically
</h4>

grep -A1 "Ready to be merged automatically" 

prints two lines but how can i use it in a if statement?

if " Ready to be merged automatically
    </h4>"
found do something.

Html file could have multiple entries of </h4> and Ready to be merged automatically, but it only has one entry together.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Mihir
  • 557
  • 1
  • 6
  • 28
  • 1
    use `-q` option... see https://unix.stackexchange.com/questions/48535/can-grep-return-true-false-or-are-there-alternative-methods – Sundeep Nov 22 '16 at 16:31
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Nov 22 '16 at 16:52
  • 1
    @Sundeep `grep -q` will just tell if the first line is found, it won't tell if it's followed by `` – Barmar Nov 22 '16 at 16:59
  • 1
    This seems like a better job for `awk`. When you match the first line, read another line and test if it matches the second line. – Barmar Nov 22 '16 at 17:00
  • not sure why this question was marked not useful. I searched everwhere, grep -q won't tell if its followed by . – Mihir Nov 22 '16 at 17:23
  • 1
    @Barmar oh ok, I hadn't read the question properly then... `awk` would be better fit as you point out... `awk 'p ~ /Ready to be merged automatically/ && /<\/h4>/{print "matched"} {p = $0}' file` – Sundeep Nov 23 '16 at 01:51
  • @Sundeep - thank you, above awk statement worked. – Mihir Nov 23 '16 at 04:46
  • grep -Pzo 'Ready to be merged automatically.*\n.*' file, if anyone needed a one liner in grep. – Mihir Dec 02 '16 at 16:19

0 Answers0