Issue
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?
Solution
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".
Answered By - Vincent Fourmond Answer Checked By - Willingham (WPSolving Volunteer)