Practice Use drills for recall and labs for real operating judgment.

LAB-TEXT-05 - Sorting & Uniqueness

Use sort, uniq, and wc to organize text, count repeated values, and rank the most common entries.

TXT Text Processing

Sorting & Uniqueness

Use sort, uniq, and wc to organize text, count repeated values, and rank the most common entries.

25 min BEGINNER LINUX Curriculum-reviewed
Success criteria
  • Use sort, uniq, and wc to organize text, count repeated values, and rank the most common entries.
  • Repeat the workflow without copy-paste or step-by-step prompting.
Safety notes
  • Practice counting and ranking on sample text first so you can see exactly how each command changes the data.

Part A: The Field Guide


What This Lab Is Really About

Once you can filter and extract text, the next useful step is counting patterns.

This lab teaches a small but powerful sequence:

  • organize the data with sort
  • count repeated lines with uniq -c
  • rank the counts with sort -nr

Command Reference

Core counting pipeline

sort items.txt sort items.txt | uniq sort items.txt | uniq -c sort items.txt | uniq -c | sort -nr wc -l items.txt


Part B: The Drill Deck

Terminal required: work inside a disposable practice folder.


G
Guided Step by step - type exactly this and compare the result
>

Exercise G1: Sort Numbers Correctly

  1. Create a practice folder:
mkdir -p "$HOME/sort_lab"
cd "$HOME/sort_lab"
  1. Create a number list:
printf "1\n10\n2\n25\n3\n" > numbers.txt
  1. Compare:
sort numbers.txt
sort -n numbers.txt
  1. Confirm why numeric sort matters.

Exercise G2: Count Duplicates

  1. Create a list with repeated values:
printf "apple\nbanana\napple\ncherry\napple\nbanana\n" > fruits.txt
  1. Count duplicates the right way:
sort fruits.txt | uniq -c
  1. Confirm why sorting comes first.

Exercise G3: Rank the Counts

  1. Add one more sort:
sort fruits.txt | uniq -c | sort -nr
  1. Confirm that the most common value is now at the top.
S
Solo Task described, hints available - figure it out
>

Exercise S1: Count Total Lines

  1. Count the total number of fruit entries:
wc -l fruits.txt
  1. Compare that total to the number of unique fruits you saw after uniq.

Exercise S2: Count Repeated Paths

  1. Create a small request list:
printf "/\n/login\n/\n/status\n/login\n/\n" > paths.txt
  1. Use a pipeline to count and rank the repeated paths.
M
Mission Real scenario - no hints, combine multiple skills
>

Mission M1: Find the Top 3 Requested Paths

Create a file named requests.log with this content:

GET /
POST /login
GET /
GET /status
POST /login
GET /
GET /docs

Now build a pipeline that:

  1. extracts only the path column
  2. sorts the paths
  3. counts duplicates
  4. ranks the counts from highest to lowest
  5. shows only the top three results

If you can explain what each stage contributes, the mission is complete.