3 added 5 characters in body
source | link

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail*Fail\n)/#\1#\2#\3#\1#\2#\3#/g' file

Here is how it works:

  • -p: print program in the loop over all input lines
  • -0: assume null as record separator
  • -e: execute program from the command line
  • s/x/y/g: substitute y for x anywhere in the file
  • (): group together regular expressions
  • .*: any character except newline repeated zero or more times
  • \n: newline
  • \1,\2,\3: access pattern from nth group ()

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult#Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult#Reasult
Name
Number
Reason = Pass
Reasult

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail)/#\1#\2#\3/g' file

Here is how it works:

  • -p: print program in the loop over all input lines
  • -0: assume null as record separator
  • -e: execute program from the command line
  • s/x/y/g: substitute y for x anywhere in the file
  • (): group together regular expressions
  • .*: any character except newline
  • \n: newline
  • \1,\2,\3: access pattern from nth group ()

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail\n)/#\1#\2#\3#/g' file

Here is how it works:

  • -p: print program in the loop over all input lines
  • -0: assume null as record separator
  • -e: execute program from the command line
  • s/x/y/g: substitute y for x anywhere in the file
  • (): group together regular expressions
  • .*: any character except newline repeated zero or more times
  • \n: newline
  • \1,\2,\3: access pattern from nth group ()

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
#Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
#Reasult
Name
Number
Reason = Pass
Reasult
2 added 286 characters in body
source | link

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail)/#\1#\2#\3/g' file

Here is how it works:

  • -p: print program in the loop over all input lines
  • -0: assume null as record separator
  • -e: execute program from the command line
  • s/x/y/g: substitute y for x anywhere in the file
  • (): group together regular expressions
  • .*: any character except newline
  • \n: newline
  • \1,\2,\3: access pattern from nth group ()

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail)/#\1#\2#\3/g' file

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail)/#\1#\2#\3/g' file

Here is how it works:

  • -p: print program in the loop over all input lines
  • -0: assume null as record separator
  • -e: execute program from the command line
  • s/x/y/g: substitute y for x anywhere in the file
  • (): group together regular expressions
  • .*: any character except newline
  • \n: newline
  • \1,\2,\3: access pattern from nth group ()

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
1
source | link

I would suggest to use perl:

perl -p0e 's/(.*\n)(.*\n)(.*Fail)/#\1#\2#\3/g' file

Output:

Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
#Name
#Number
#Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult