Learning the Command Line: Regular Expressions & Advanced Grep
2025-09-26
wc, grep, and |wc file.txt → identify number of lines, words, and characters in file.txt
-l, -w, -cgrep "word" file.txt → search for a string in a filegrep "word" file.txt | wc -lUsing Terminal:
alicealice.txtToday we’ll learn how basic regex commands can be used in the Terminal
While we’re currently working in the Terminal, we will return to all of this later in the semester once we have some Python under our belts
-E
grep to use Extended Regular Expressions. do?. → any single charactercat”?Note that \s = any whitespace (not just space!)
How would we say “ends with cat”?
cat or cats”?regex to workalice.txt, using grep -E, find:
\?);\1 to capture the exact same text as the previous group; thus ([tp])\1 = “tt”, “pp”);