0

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

aspell dump master | grep ozz | grep -v '[^A-Z]'
9
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.

  • Less complicated than mine :-) – sparticvs Dec 18 '13 at 21:38
2

To remove only lines beginning with a capital letter:

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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