Why not just do the following: sort -c filename If sort returns nothing, the words are sorted. If the words are not sorted, sort will return something along the lines of: sort: filename:15: disorder: abbs You can also do the following if you just want to know if the words are sorted. sort -c filename 2>/dev/null && echo Already Sorted || echo Not Sorted I don't know the specifics of why grep is being used or the problem, but damn that is overkill just to find out if a list of words are sorted. 'man sort' will give you are the details for using sort.