Handle DOS and Unix line endings correctly