Lullabot Ideas
We know stuff. We empower you to know stuff too.
Command Line Basics: grep is your friend
Video by Addison BerryJune 22, 2010 - 6:02pm
Search for text within files
Watch the video on Drupalize.me
This video in the command line series will get you started using the very powerful grep command. This is one of the most used commands, especially if you are working with a lot of text (like code, for instance). Grep will let you search through files to find strings and it's great for tracking down where something is coming from. Grep is a very powerful tool with lots of options, but you'll see you can do a lot even with just the basics. We cover the basic command with a file, how to use it through directories, and then we use a few of the most popular options:
-r Recurse
-n Line Number
-l List
-v Reverse
-i Ignore Case

Comments
*gasp* does this mean awk/sed
*gasp* does this mean awk/sed are on the way?
even better
ack -- can be installed as standalone and as a perl script it's likely you can "install" it anywhere. http://betterthangrep.com/
Skip over SVN/CVS files?
Great video.
Typically, my Drupal installs will be checked out from CVS and then thrown into my own SVN repository. Is there a way to grep through a Drupal install like that skipping over files inside of .svn/ and CVS/ directories?
Thanks,
Matt
Matt; You can use the
Matt; You can use the
--exclude=[file]and--exclude-dir=[dir]flags to exclude particular files and directories from a recursive search. For example, this will not find matches in any files with filenames that begin with a dot, and not recurse inside any directories named CVS:grep foo -r my_module --exclude=".*" --exclude-dir="CVS"A couple more handy flags: The
-Cflag, when followed by a number…grep foo -n -C 4 -r my_module…will print out the 4 (or whatever number you specify) lines before and after the matching line, which provides a bit more context about where in the file the matching line is found. Also, if your terminal program supports it, the
--colorflag will color code the output, highlighting the part of the line that the pattern matched in red, for example.Good stuff,thank you for
Good stuff,thank you for share
Thanks for the lesson
Thanks for the lesson ! Grep is super-powerful :)
Great tutorial
Wonderful video and a short tutorial you've provided. It really makes it easy for. It is complicated but more accurate and understandable. Thanks for sharing! (Turning Winds)
Excellent stuff
WOW! Really excellent and well handled post. I learned some new basics from here. Strong tutorial really. Thanks for sharing.
wow
Thank you so much for your tutorials. I just discovered these.
Your voice is clear, well paced and relaxing to listen to.
You pace the material smoothly and manage too put in just enough information without any excessive fluff or blah blah.
And it's free!
regards