Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to find any lines in a file that exceed 79 characters?

share|improve this question
up vote 34 down vote accepted

In order of decreasing speed according to my tests:

grep '.\{80\}' file

perl -nle 'print if length$_>79' file

awk 'length($0)>79' file

sed -n '/.\{80\}/p' file
share|improve this answer
What do you mean by "efficient"? – bladezzz Jul 12 '12 at 18:30
I think manatwork means typing efficiency. awk can come closer if you drop ($0), which is implicit anyway ;). – Thor Jul 12 '12 at 18:36
BTW, if you anchor the regexp to the beginning of the line with ^, it's slightly faster: e.g. grep '^.\{80\}' file. – cas Jul 29 '12 at 9:32
The perl solution does not account for variable size encoding such as UTF-8, unlike all the other solutions. – BatchyX Jan 30 '13 at 16:19
Sufficiently large values of N fail with grep but succeed with awk. (e.g. grep '^.\{1000\}' file returns grep: invalid repetition count(s), while awk 'length>1000' file succeeds.) – mdahlman Dec 18 '14 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.