AMit SiNgh
AMit SiNgh

Reputation: 325

grep linux command exclude if file name contains integer

Print only those files whose file name does not have any integer.

example:

httpdocs/bak_2016-01-10-embed.php:function displayVideo
httpdocs/bak_EMBED_embed.php:function displayVideo_flv($path,$au

Only show 2 file.

I am trying the below command but it is not working.

egrep -r --exclude='[^0-9]+\.*' "n displayVideo"

Upvotes: 0

Views: 258

Answers (1)

nu11p01n73R
nu11p01n73R

Reputation: 26667

The problem is that your exclude pattern is wrong.

As per man page,

--exclude=GLOB

Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.

  • + is not a valid glob character.
  • To negate a class in glob we use [!...] where is [^..] is a regex syntax.

  • More about globbing


Instead you can write

$ egrep -r --exclude=*[0-9]* "n displayVideo"
  • *[0-9]* This pattern matches all those file names which contains at least 1 digit in it.

Upvotes: 1

Related Questions