Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

>_
Terminal & Command Line
0/10 completed
Beginner
What is the terminal?Navigating foldersWorking with files and foldersViewing files
Intermediate
Wildcards and finding filesPipes and redirectionText processing: grep, sort, cut and friends
Advanced
Environment variables and PATHPermissions and processes
Pro
Shell productivity: aliases, scripts and dotfiles
Tracks / Terminal & Command Line / Intermediate

Text processing: grep, sort, cut and friends

Logs, CSVs, configs and code are all text. A handful of tiny tools let you search, slice and summarise text faster than opening a spreadsheet. Developers and DevOps engineers use these daily to investigate incidents.

grep: search for text

Linux terminal (simulator) · editable
Flag Meaning
-i Ignore case
-n Show line numbers
-c Count matching lines
-v Invert: show lines that don't match
-r Search recursively through folders
-l Only list the names of files that match
-o Print only the matching part
-E Extended regular expressions (a|b, +, ?)

Search a whole project

Linux terminal (simulator) · editable

This finds every TODO in your codebase with its file name and line number. (Modern alternative: ripgrep, rg TODO, which is much faster on big projects.)

Patterns: regular expressions

grep understands regular expressions, a mini-language for text patterns:

Linux terminal (simulator) · editable
Pattern Matches
^text A line starting with text
text$ A line ending with text
. Any single character
[0-9] Any digit
* / + Zero or more / one or more of the previous item
a|b a or b (with -E)

cut: select columns

data/sales.csv has the columns date,region,product,amount:

Linux terminal (simulator) · editable
  • -d, sets the delimiter (the separator) to a comma.
  • -f2 picks field (column) 2, and -f3,4 picks fields 3 and 4.

sort and uniq: summarise

Linux terminal (simulator) · editable

That one line answers "How many sales did each region make?" Let's break it down:

  1. cut -d, -f2 → just the region column
  2. tail -n +2 → skip the header row
  3. sort → group identical regions together
  4. uniq -c → count each group
  5. sort -rn → biggest first

Sorting by a column

Linux terminal (simulator) · editable

-t, sets the separator and -k4 sorts by the 4th column. -n makes the sort numeric, so "219" comes after "45".

tr and sed: transform text

Linux terminal (simulator) · editable
  • tr translates or deletes characters.
  • sed 's/old/new/g' substitutes text on every line (g = every match on the line, not just the first). It's the classic "find and replace" in pipelines. sed -i edits files in place on real machines.

Real-world investigation

"Payments are failing! Which orders were affected?"

Linux terminal (simulator) · editable

"How many requests did each API endpoint get?"

Linux terminal (simulator) · editable

awk: a mini programming language

On real machines, awk handles column maths that the simpler tools can't:

bash
awk -F, 'NR > 1 { total += $4 } END { print "Revenue:", total }' sales.csv
awk -F, '{ sum[$2] += $4 } END { for (r in sum) print r, sum[r] }' sales.csv

Practice

Using data/sales.csv and data/app.log:

  1. How many sales were for Laptop?
  2. List the distinct products sold, alphabetically.
  3. Show every log line that is not INFO, with line numbers.
  4. Which region had the single biggest sale? (Hint: sort by amount, take the last line, cut the region.)
Linux terminal (simulator) · editable
✎ Check your understanding

1.Which command counts the lines in app.log that contain "ERROR"?

2.What does cut -d, -f2 file.csv do?

← Pipes and redirection