Joshi
Joshi

Reputation: 2790

search recursively using grep for any string of specific length without spaces

I am trying to search for any string of say more than 200 characters without any space character in between.

I have tried multiple options, but nothing seems to work.

for example

grep -r '.{200,}' /directory/sub-directory/

grep -r '[^\s.]{200,}' /directory/sub-directory/

Upvotes: 0

Views: 675

Answers (2)

jdurkin
jdurkin

Reputation: 146

grep -o -E '\S{200,}' -r /directory

  • -o will only return the matching string instead of the whole line
  • \S will match any non-whitespace

The rest you had already

Upvotes: 1

ilkkachu
ilkkachu

Reputation: 6517

The {n,m} specifier requires extended regexes (grep -E), and if you want anything but space, [^ ] should do. Also, "more than 200" is the same as "at least 201", so:

grep -rEe '[^ ]{201,}' path

Upvotes: 1

Related Questions