in the above example i would want some counter variable incremented everytime a \n is printed. The end goal is that when a cetain number of lines is reached i want to close the file handle, and open a new one with the same name that points to a different file.