Hi everyone,
I know there have been slightly similar posts for counting the number of lines between specific words, but none of them were quite what I'm looking for.
I have a .txt file with all my data, and I've set it up so it looks something like this:
1 2 3 4 5 6 7 8 9
Line
(data)
(data)
(data)
End
Line
(data)
(data)
End
and etc. So what I've been struggling to find is a way to count the number of lines in between 'Line' and 'End' for each set. I of course do not want to do this by hand as there are 1000 data sets. There are also some data sets that are empty, and so would appear like:
Open the file, while(has next line) read line, if it's Line, start new count, if it's end, display count, otherwise count++, read everything between the newline character as a line, so
1 2 3 4
Line\n
data\n
data\n
End\n
read everything into a buffer until you reach the newline character, then check to see if that buffer is either line or end.
If you need help with any individual step, let us know.
Have you defined the function count()? What did you expect to happen? You're trying to call a function that doesn't exist, so of course it's not defined in this scope.
After a bit more searching around on my own I found this beautiful solution on the internet and it worked perfectly after I trimmed my log5.txt file a bit more: awk ' /List/ { if ( f!="") {print f-1}; f=0;f1=1 } f1 { f++ } ' log5.txt > newlog5.txt