Learn to search for text patterns at the Linux command line.
Linux grep command summary with examples (3:30)
Videos can also be accessed from the YouTube Playlist.
Our thirty-ninth word, or command to memorize is
grep from our category
grep allows you to search for text
patterns in a file.
Recall from recent videos, we've been sorting, cutting, pasting and joining files together. Now we'll advance by searching whole files of text.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
join command has
over 40 options, and the arguments represents the
file you'd like to read.
Like most commands, help is available with double-dash
--help. And because
grep is so advanced and important,
I'll keep it simple here and later refer you to a helpful reading.
So why is
grep an important command?
Well, just like the search feature in a word processor, this Linux
command is very useful for finding text patterns.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. Remember back a few videos ago, we saw a misspelled word
in one of our text files? I typed "thrid", instead of "third", so let's
grep to look for it. I don't
recall exactly where, but it was one of the videos in the 20s, I think.
So let's use
grep with the
--color option and in quotes type
There it is, in
highlighted in a different color.
Then we'll add the
-c option to count
the number of places it has been misspelled, and broaden the search
to include all files.
And wow, there are more than I thought.
And last, let's throw in the
to include a line number, so we can get after these and tidy up,
because we do like accuracy.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
So I only touched on the vast power of
grep. In the Comments section find a
link to a helpful page on Wikipedia on what are called
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Learn faster by combining this page with the video. Subscribe here.
joincommand, hit Back.
sed, click Next.