Reputation: 649
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
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
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
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