Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all lines containing more than a certain number of letters?

Tags:

bash

How can I delete all of the lines in a file which contain more than a given number of letters? E.g.

bear
rabbit
tree
elephant

If I restrict it to words of 5 letters or less, the output would be:

bear
tree
  • The file contains various foreign characters, each of these should count as one letter.
  • Punctuation symbols also can count as one letter.
like image 757
Village Avatar asked Nov 27 '22 06:11

Village


1 Answers

$ awk 'length<=5' input.txt
bear
tree
like image 167
kev Avatar answered Dec 23 '22 09:12

kev