I have a series of files that look like the below, I need to group them into "consecutive groups", each line starts with a number, the file should be read from top to bottom, and if the next line below is the same number or 1 less than the line above, they should be "grouped" together, this should also be the case if there are multiple lines together.
The aim at the end is to have a number generated from the file of individual "groups" where the closest number to each one is more than one away. I have shown the desired output below the example file below.
78' Corner, Bristol City. Conceded by Wes Hoolahan. 75' Corner, Bristol City. Conceded by Ahmed Hegazi. 60' Corner, Bristol City. Conceded by Ahmed Hegazi. 51' Corner, Bristol City. Conceded by Sam Johnstone. 20' Corner, West Bromwich Albion. Conceded by Niki Mäenpää. 19' Corner, West Bromwich Albion. Conceded by Adam Webster. 13' Corner, Bristol City. Conceded by Ahmed Hegazi. 7' Corner, Bristol City. Conceded by Sam Johnstone. 2' Corner, Bristol City. Conceded by Sam Johnstone.
The overall aim is to get a total number where the matches in the line are more than 1 apart, so this file has 9 lines, which I can get from a simple
wc -l. I want the ability to run a script / command line to get a number of independent matches.
So in the above example "19 & 20" should be grouped together, so the total count would be 8 "independent" lines. (A line counting as independent if it is at least 1 away from any other number).
If there was a line starting with 21 for example in the above example the output would still be 8 as that would be grouped with the "19 & 20" hits, it is also possible that there would be lines with the same number for example "19 & 19".
I'm not sure how possible this is without writing a more complex script to take into account the requirements but I've seen some impressive sed/awk lines in my time so may be a job for one of those.