helper function for sorting lines with case-insensitive option