My intention is to search for a string in specific file format recursively in the current directory. From SO I found this find command to search
find . -type f -name '*.extension' | xargs grep -i string
But this was too lengthy and I found this really hard to remember. So, I tried to write a function and add it to my .bash_profile
something like this
function search {
echo `find . -type f -name '*.$1' | xargs grep -ir '$2'`
}
and the other one which I've tried is
function search {
echo `find . -type f -name '*.$1' | xargs grep -ir '$2'`
}
Both didn't print any results on the screen when I invoke my as
search txt mysearchstring
though I have few .txt
files in the directory which contains the word mysearchstring
. I'm not sure what makes me go wrong. Can someone help me on this?