问题
I have a dictionary with words separated by line breaks.
回答1:
You can just do:
egrep -x '.{1,3}' myfile
This will also skip blank lines, which are technically not words. Unfortunately, the above reg-ex will count apostrophes in contractions as letters as well as hyphens in hyphenated compound words. Hyphenated compound words are not a problem at such a low letter count, but I am not sure whether or not you want to count apostrophes in contractions, which are possible (e.g., I'm). You can try to use a reg-ex such as:
egrep -x '\w{1,3}' myfile
..., but this will only match upper/lower case letters and not match contractions or hyphenated compound words at all.
回答2:
Like this:
grep -v "^...." my_file
回答3:
Try this regular expression:
grep -E '^.{1,3}$' your_dictionary
来源:https://stackoverflow.com/questions/4982052/how-do-i-grep-for-all-words-that-are-less-than-4-characters