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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
The importance of modularity2m 37s
-
(Locked)
Use pipes to connect commands together2m 54s
-
(Locked)
View text files with cat, head, tail, and less4m 46s
-
(Locked)
Search for text in files and streams with grep5m 21s
-
(Locked)
Manipulate text with awk, sed, and sort7m 33s
-
(Locked)
Edit text with Vim5m 14s
-
(Locked)
Edit text with nano2m 38s
-
(Locked)
Working with tar and zip archives9m 26s
-
(Locked)
Challenge: Create and share a file24s
-
(Locked)
Solution: Create and share a file1m 41s
-
(Locked)
Output redirection5m 38s
-
(Locked)
Exploring environment variables and PATH4m 20s
-
(Locked)
Challenge: Extract information from a text file1m 2s
-
(Locked)
Solution: Extract information from a text file4m
-
(Locked)
-
-