0

-----my input file [file name -- test]

    centos is my bro
    red hat is my course
    ubuntu is my OS
    fqdn is stupid 

    tom outsmart jerry   
    red hat is 3
    red hat is friend
    red hat is my boy
    jerry is small

---- my code

#! /bin/bash

grep -C1   --color=always "red hat" test
 

--- expected output

 centos is my bro
 red hat is my course
 ubuntu is my OS     
 --
 tom outsmart jerry   
 red hat is 3
 red hat is friend
 --
 red hat is 3
 red hat is friend
 red hat is my boy
 --
 red hat is friend
 red hat is my boy
 jerry is small

---- coming OUTPUT

    centos is my bro
    red hat is my course
    ubuntu is my OS
    --
    tom outsmart jerry   
    red hat is 3
    red hat is friend
    red hat is my boy
    jerry is small

---- please provide the necessary option for the grep command to get the expected output

----- if there is some other way to achieve this output

----- please give reference and the comments in the code

  • 2
    I do not think there is such option. Write it yourself, in `awk` should be simple. – KamilCuk Aug 21 '20 at 10:26
  • 1
    yep, grep doesn't have an option to do this, at least on the implementations I've used so far.. – Sundeep Aug 21 '20 at 10:28
  • I already showed you how to do that in your previous question, https://stackoverflow.com/q/63416009/1745001 – Ed Morton Aug 21 '20 at 13:36
  • Does this answer your question? [how can i loop through the coming frequency of the keyword](https://stackoverflow.com/questions/63416009/how-can-i-loop-through-the-coming-frequency-of-the-keyword) – Nic3500 Aug 22 '20 at 02:12
  • @Ed Morton i tried to run the solution but it doesn't run and can you provide comments how it is working please sir – Aditya Singh Aug 22 '20 at 08:07

0 Answers0