try to read until a valid line appears