Bitpath

Lesson 2 · Unit 02

Filters

grep, sort, uniq, cut, tr, and a first taste of sed and awk

13 exercisesabout 3 min

What you practise

  • grep (-i, -v, -r, -n, -c), sort (-n, -r, -k), uniq -c, cut, tr, a first taste of sed 's/a/b/' and awk '{print $1}'

Try a question from this lesson

Pick one

The lines between the two EOF markers become the file app.log. grep prints the lines that contain a pattern. What does it print here?

shell
cat > app.log <<EOF
error: disk full
all good
Error: no network
EOF
grep error app.log

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

sort and uniq

sort puts lines in order. It compares them as text unless you say otherwise, and as text 10 comes before 9, because 1 comes before 9.

uniq removes repeated lines, but only repeats that are next to each other. With -c it also counts each run.

shell
sort names.txt     # as text, A to Z
sort -n sizes.txt  # as numbers
sort -r names.txt  # reversed
sort -k 2 t.txt    # by the 2nd field
sort f | uniq      # drop repeats
sort f | uniq -c   # and count them

11 more exercises in the app

  • 2× fill the blanks
  • 4× type the answer
  • 3× multiple choice
  • 1× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy