Perl script to delimit size of strings

Hello,
I have a huge file of over 2,00,00,00 strings in UTF8 format. I have managed to write a script in Perl which sorts them neatly as per their Unicode ranges.
However I am now stuck with a script which will pipe out all strings between 3 and 20 letters/characters. I am not very good at writing size delimiters in Perl and if someone could help me out with a small script, it would be a great learning
experience for me.
Thus given

to
at
in
dog
whether
for
insoluble
supercalifragilisticexpialidociously

The output should be

dog
whether
for
insoluble

since all the other words are either less than 3 or greater than 20 (only one instance here)
Many thanks in advance for help

Try:

perl -nle 'print if length()>2&&length()<21' file

Another one:

$
$ cat f61
to
at
in
dog
whether
for
insoluble
supercalifragilisticexpialidociously
$
$ perl -lne 'print if /^\w{3,20}$/' f61
dog
whether
for
insoluble
$
$

tyler_durden

1 Like