Add lesson 4: grep, sort and uniq

Sam Okafor 1 year ago
parent b29576d46f commit 84b5ceb6257368614cc12ff3f9979c7c6fbca056
3 changed files with 32 additions and 0 deletions
+19-0lessons/04-grep-sort-and-uniq/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 4: grep, sort and uniq
2+
3+We look at grep, sort and uniq the way working developers use it, with examples you can change and run right away.
4+
5+Full lesson: [https://glibcode.net/courses/linux-shell/lessons/4](https://glibcode.net/courses/linux-shell/lessons/4)
6+
7+## Files
8+
9+- `logs.sh`: grep, sort and uniq on a web server log
10+
11+## Run it
12+
13+```sh
14+sh logs.sh
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+5-0lessons/04-grep-sort-and-uniq/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 4
2+
3+1. Break the example on purpose: delete a bracket or misspell a name. Read the error message. Which line does it point to?
4+2. Make the example ask for its input instead of using a fixed value.
5+3. Time yourself: rewrite the example from memory in 10 minutes, then diff it against the original.
+8-0lessons/04-grep-sort-and-uniq/logs.sh ADDED
@@ -0,0 +1,8 @@
1+# Which IPs hit us most?
2+cut -d' ' -f1 access.log | sort | uniq -c | sort -rn | head
3+
4+# All 404s, newest last
5+grep ' 404 ' access.log | tail -20
6+
7+# Lines with "error", case-insensitive, with line numbers
8+grep -in error app.log