Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why does the following command still return some lines containing a capital letter?

aspell dump master | grep ozz | grep -v '[^A-Z]'
share|improve this question

3 Answers 3

up vote 7 down vote accepted
grep -v '[^A-Z]'

removes (-v) the lines that contain a character other than the characters A to Z.

You probably want:

grep -v '[[:upper:]]'

to remove the lines with at least one upper-case letter, or:

LC_ALL=C grep -v '[A-Z]'

to remove the lines with at least one of 26 ASCII characters between A and Z.

share|improve this answer
    
Less complicated than mine :-) –  sparticvs Dec 18 '13 at 21:38

First off, you are inverting an inversion, which isn't want you want. What you are looking for is more like this:

aspell dump master | grep ozz | grep '^[^A-Z]*$'

Explained

You are matching on individual characters. You need to match on more than just 1 (if you want to only select lines that don't have caps). So we add the asterisk (*) to the end. This means, I am looking for lines that have 0 or more non-capital letters. We add the caret (^) to the front and the dollar sign ($) to the end to denote, from the beginning of the line to the end of the line. So this can be read as, from the beginning of the line to the end of the line, 0 or more characters that don't contain any character from A-Z.

Hope this helped.

share|improve this answer

To remove only lines beginning with a capital letter:

aspell dump master | grep ozz | grep -v '^[[:upper:]]'
share|improve this answer
    
I think he doesn't want any capitals –  sparticvs Dec 18 '13 at 21:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.