How can I select lines containing specific values?
head and tail select rows,
cut selects columns,
and grep selects lines according to what they contain.
In its simplest form,
grep takes a piece of text followed by one or more filenames
and prints all of the lines in those files that contain that text.
For example,
grep bicuspid seasonal/winter.csv
prints lines from winter.csv that contain "bicuspid".
grep can search for patterns as well;
we will explore those in the next course.
What's more important right now is some of grep's more common flags:
-c: print a count of matching lines rather than the lines themselves-h: do not print the names of files when searching multiple files-i: ignore case (e.g., treat "Regression" and "regression" as matches)-l: print the names of files that contain matches, not the matches-n: print line numbers for matching lines-v: invert the match, i.e., only show lines that don't match
This exercise is part of the course
Introduction to Shell
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
Start Exercise