From the course: Learning Linux Command Line

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Search for text in files and streams with grep

Search for text in files and streams with grep - Linux Tutorial

From the course: Learning Linux Command Line

Search for text in files and streams with grep

- [Instructor] One of the main reasons we'd want to take a look at text files is to find and use some particular piece of information they contain. A popular command we can use to do that without reading over a whole file ourselves manually is grep. At its most basic, grep returns or outputs lines of text that match a search condition called a pattern. The pattern can be either a specific or explicit group of characters, or we can use a pattern called a regular expression. We'll take a look at both briefly here, but grep is a hugely powerful tool, and it's worth a course of its own. We'll take a look at the basics so you're prepared to dive in deeper if you want to. Let's use grep to look for some text in our poem's exercise file. First we'll have grep show us all the lines of our poem's file that have the letters, T, H, and E right together. To do this, I'll write grep and then the search term inside quotes, that'll be "the" and then the name of the file that I want to look inside…

Contents