Take the 2-minute tour ×

I'm looking for a way to grep things like: i log for E M, i 1 f x i 0, I xi 1, 3 1,. simply based on number of characters.

Nothing in that hypothetical output is longer than three characters. This hypothetical one-liner would look something like, grep -v [:alnum:] > {3}. (Except I just don't know how to write that in grep syntax.)

share|improve this question
Do you want to match characters like , and . as part of a word? –  Herman Torjussen Feb 24 '12 at 17:31
add comment

1 Answer

up vote 8 down vote accepted
grep -o -w '\w\{1,3\}' data

Options are:

  • -o print only matched words
  • -w match only whole words

It matches only words (in grep \w = [[:alnum:]] = [A-Za-z0-9]) of length from 1 to 3 (specified by {1,3})

share|improve this answer
thanks. the basic syntax of your answer is what i needed, and i ended up just using grep '\w\{3}' data and the same command with grep -v.. –  ixtmixilix Feb 26 '12 at 21:29
add comment

Your Answer


