1

Let's see if we want to find all file name as below format

gstreamer_abc.c
gstreamer_xyz.c
gstreamer_abcxyz.c

then we can use find command as below

find ./ -iname "gstreamer_*.c"

Same way i need to grep some APIs in file as below

gstABCNode()
gstAnythingCanBeHereNode()
gstXyzNode()

I am trying something

grep -rni "gst*Node"  ./
grep -rni "gst^\*Node" ./

But it does not gives what i need here. First is it possible to search with grep like this or if possible then how to grep such pattern?

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222

2 Answers2

1

You can grep only these files:

grep --include "gstreamer_*.c" -rni "gst*Node"  ./
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
1

Your problem is that find uses "globs" while grep uses regular expressions. With find, * means "a string of any length". With grep, * means "any number of times the element (character) that precedes". This way, your command:

grep -rni "gst*Node"  ./

searches for any string that starts with gs, any number of times t, and Node (which is presumably not what you want). Try rather:

grep -rni "gst.*Node"  ./

The . means "any character", so .* really means "a string of any length".

Vincent Fourmond
  • 3,038
  • 1
  • 22
  • 24