I'm trying to get familiar with the basics of the terminal. I'd like to find the file within my CMS website that contains my Google Analytics tracking code "gaq" as a string to search should do the trick.
There is a folder on my desktop that contains all of the sites files.
/Users/myname/Desktop/website
I opened the terminal and tried
grep gaq /Users/myname/Desktop/website
grep gaq * /Users/myname/Desktop/website
I searched on SO and Google but the internet seems crowded out with slightly more advanced uses of grep involving regular expressions and conditions.
e.g.: Unix Command to List files containing string but *NOT* containing another string, How can I use grep to find a word inside a folder?.
I thought I'd found the answer with the second example question. I tried the following command: grep -nr gaq* /Users/myname/Desktop/website
But that returned many results and, from what I can see, not exactly accurate matches of my search string.
Here's a sample of the Google Analytics snippet, taken by viewing the source of the html page. My goal is to find the file that generates the analytics snippet in order to update it to the newer version of Google Analytics:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_gaq.push(['_trackPageview']);
So I am using "gaq" as a string to search for.
I realize that this must sound pretty basic but it's pretty frustrating as a beginner to the shell.
How would I search the directory /Users/myname/Desktop/website for the file (return the file not the actual paragraph of text) that contains the analytics code using grep (assuming grep is the command I should be using?)