Q . grep command - exclude if file name contains integer.

Dev Singh. asked, Jan 11 ' 2017

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 second one file.

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

egrep -r --exclude=*[0-9]+* "n displayVideo"

 

  • linux
  • bash
  • grep

1 Answers

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.

 

Source : stackoverflow

Leave a Ansewer