RRC|BIOSTATISTICS

Searching for a Pattern

I was struggling to make major changes with my Octopress website since everything is nested and calls to different folders.

I found a thorough writeup of a solution on Stackoverflow

This is the simple version: grep -rnw '/path/to/somewhere/' -e "pattern" This is my example: grep -rnw ~/octopress/ -e "twitter-follow-button"

In this case for grep -r or -R is recursive; you’re searching through all directories and subdirectories
-n is line number; so you know where it is in that file
-w matches the whole word

If you read through “Unix in a Nutshell” (one of my favorite reference books!) you will see on page 2-54 that grep will search one or more files for lines that match a regular expression. Here, -e indicates the pattern you want to match against. If you use -E then you are ignoring special characters like {, |, or ).

Comments