grep and Repetitions

A few days ago I was trying to achieve something with grep (which is usually not a big problem) and a large file with one word per line (a dictionary). I wanted to grep out all the lines which contained words with three or less characters. And after wasting some time I decided to write a note to myself:

If you have a file like this:

yyy@xxx:~$ cat bla

and use grep like this

yyy@xxx:~$ grep "^.{1,3}$" bla

then you don’t get any output.
It also won’t help if you add -e. You will have to add -E in order to activate extended regular expressions, or you can call egrep(which is deprecated).

yyy@xxx:~$ grep -E "^.{1,3}$" bla

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − = 1

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>