Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use grep to find terms that are n characters long?

Tags:

regex

grep

I'm using grep to filter the Mac OS X dictionary words file (by default located at /usr/share/dict/words).

I want to use grep to retrieve all words four characters long. How do I do this?

My best guess for how to do this was:

grep [:alpha:]{4} words

But that returns zero results.

like image 781
Brian Willis Avatar asked May 22 '10 07:05

Brian Willis


1 Answers

Trying to remember how much of regex language grep supports... does

grep '^....$' words

work for you? Note that since you are searching a dictionary file, I'm not sure you need to restrict yourself to letters.

like image 161
AakashM Avatar answered Sep 26 '22 08:09

AakashM