1

Is there a way to write the following command more concisely?

grep -E '[A-Z](([a-z]{2})|([a-z]{3})|([a-z]{4}))' file.txt
Enlico
  • 23,259
  • 6
  • 48
  • 102
Destiny
  • 19
  • 1

1 Answers1

0

Instead of using an alternation | for every quantifier {2}, {3}, {4} in a separate capturing group you could use a single quantifier {2,4} and a single capturing group.

grep -E '[A-Z]([a-z]{2,4})' file.txt

About the pattern

  • [A-Z] Match single char A-Z
  • ( Capture group 1
    • [a-z]{2,4} match 2-4 times a-z
  • ) Close group
The fourth bird
  • 154,723
  • 16
  • 55
  • 70