Why this exclusion not working for long sentences?

100 views Asked by At

Command

perl -ne 'print unless /.[240,]/' input.txt > output.txt

which includes some sentences which are longer than 240 letters. Why?

Example data

Development of World Funny Society program on young people who are working hard for the sport and social life such that they have time to go pizzeria every now and then and do some fun, programming and having great breakfast:| World scenario of free time programs are often too long such that this star probably makes the program upset (*)|Again a very long option which is not probably the reason which makes this program upset|good shorter option which is ok but nice to write here coffee morning messages|c last option is always good one because you know that you can soon stop 1

Example data 2

Indications of this program depends on many things and I like much more this than Lorem ipsum which is too generic and takes too much time to open:|short option just in case|little longer option so good to have it here too|shorter which is better too but how much is the question|shortest is not the least|longer one once again but not too long 1

1

There are 1 answers

3
kos On BEST ANSWER

You're using the wrong syntax: [] is used to match a character class, while here you're trying to match a number of occurences of ., which can be done using {}:

perl -ne 'print unless /.{240,}/' input.txt > output.txt

Also, as suggested by salva in the comments, the pattern can be shortened to .{240}:

perl -ne 'print unless /.{240}/' input.txt > output.txt