Can this be done with sed/awk/grep or other unix tools?
Yes.
...
It can be done using tools like awk or perl in about 20 lines of code.
$ cat t.txt
194104,41.8,38.3
194104,46.7,39.6
194104,47.4,39.7
194104,49.8,44.3
194104,50.8,47.5
194136,39.9,36.3
194136,45.2,37.8
194170,46.9,42.2
$ perl t.pl t.txt
194104,41.8,38.3
194104,46.7,39.6
194104,47.4,39.7
194104,49.8,44.3
194104,50.8,47.5
$ wc -l t.pl
19 t.pl
The basic ideas I used were
- loop over input a line at a time
- append the lines to a buffer
- check the value of the first word
- keep a count of how many times it had been seen
- if different, decide if to print and flush buffer, reset count
Pseudocode
This corresponds line by line with my perl code but perl is a bit terser
(and I cuddle my elses even though Larry disapproves).
let my minimum be 5
let my buffer be blank
let my count be zero
let my prior first word be blank
while read a line
if there is a numeric first word followed by a comma
then
if that first word was the same as my prior first word
then
increment my count
otherwise
if my count is greater than or equal to my minimum
then
print my buffer
end if
empty my buffer
let my count be one
end if
let my prior first word be the one I just read
append the line I just read to my buffer
end if
end while
It can probably be done in fewer lines or a longish one-liner.