shmnsw
shmnsw

Reputation: 649

UNIX grep command syntax for lines containing at least 35 characters

I'm trying to print only the lines that contain, let say, at least 35 characters, from a file.

How can I do this?

Upvotes: 2

Views: 1916

Answers (4)

Keith Thompson
Keith Thompson

Reputation: 263307

grep is not the best tool for this job.

You could write:

grep ................................... filename

or use one of the more sophisticated regular expression features mentioned in other answers (if your grep supports them). But awk:

awk 'length >= 35' filename

or perl:

perl -e 'print if length >= 35' filename

would be more appropriate.

Upvotes: 4

Junior Dussouillez
Junior Dussouillez

Reputation: 2397

You need to use regular expressions :

grep -E ".{35,}" file

or

cat file | grep -E ".{35,}"

The dot means a character (letter, digit), and the {35,} means at least 35 character or more.

man grep if you want more informations

Upvotes: 2

Cratylus
Cratylus

Reputation: 54074

Try: $ grep -E '^.{35,}$' the extended version of grep

Upvotes: 2

anubhava
anubhava

Reputation: 785246

grep with -P (Perl regular expression) or -E (extended regular expression) switch OR egrep should work:

grep -E '.{35,}' file

OR

grep -P '.{35,}' file

OR using egrep:

egrep '.{35,}' file

Upvotes: 4

Related Questions