0

I am trying to write a unix code where I will be to count no of rows between (ie here 2)

two "|DATE and TIME | XXXXXX |"

Is there any method I can use with combination of egrap and wc -l

Output:

|-------------------------------|

|DATE and TIME         | XXXXXX |

|-------------------------------|

| 21-NOV-2012 15:56:51 | 1259   |

| 21-NOV-2012 15:56:51 | 1364   |

|-------------------------------|

|DATE and TIME         | XXXXXX |

|-------------------------------|

| 21-NOV-2012 16:06:55 | 1259   |

| 21-NOV-2012 16:06:55 | 1364   |

|-------------------------------|
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sree
  • 399
  • 2
  • 5
  • 12

1 Answers1

0

if the expected result is 9 (since there are empty lines in your example, I don't know if they should be counted):

awk '/DATE and TIME/&&!f{f=1;next;}/DATE and TIME/&&f{print x;exit;}f{x++}' file
Kent
  • 189,393
  • 32
  • 233
  • 301
  • No, expected result was either 2 or 4. – Cœur Feb 26 '17 at 18:10
  • @Cœur there are nine lines between the two pattern matching lines in the question's input. So it works. If there is need for matching a second pattern into these lines, it should be described in question. – thanasisp Feb 26 '17 at 23:22
  • @thanasisp that's my interpretation of `ie here 2` in the question. – Cœur Feb 27 '17 at 03:17