DCubes
Linux module

Lesson 9

Peek at data from the shell

Download a tiny CSV and answer questions with head, cut, sort, and uniq.

beginner30 minRun on your machine

What you will be able to do

  • Copy a sample CSV into linux-lab/data
  • Count rows and inspect columns without a spreadsheet
  • Count unique values in a column using sort and uniq

Why this matters for DE and AI

Before pandas, Spark, or a warehouse, you should be able to ask: how many rows, what are the columns, what values appear? On a server you often have only a shell. These commands work on a 20-row file and on a 20-million-row file (slowly). They keep you honest.

We ship a tiny file, not a dataset. Download it; do not paste megabytes into a terminal.

The sample file

On this site (static file, not a program):

Download movies.csv

Save it, then copy it into the lab. If your browser saved it to Downloads:

WSL: Windows files live under /mnt/c/Users/YOURWINDOWSNAME/Downloads.

cp /mnt/c/Users/YOURWINDOWSNAME/Downloads/movies.csv ~/dcubes/linux-lab/data/

macOS:

cp ~/Downloads/movies.csv ~/dcubes/linux-lab/data/

Linux: same as macOS if the browser used ~/Downloads.

You can also fetch it with curl if you have the site URL later. For learning, copying from Downloads is enough.

If you are reading this on the same machine as a clone of the DCubes repo, copy from public/samples/movies.csv.

Concepts

The file is comma-separated: title,year,genre,minutes.

Command Use
head -n 5 data/movies.csv Header + a few rows
wc -l data/movies.csv Line count (header + rows)
cut -d, -f3 data/movies.csv Field 3, comma delimiter
sort Sort lines
uniq Collapse adjacent duplicates
uniq -c Count adjacent duplicates

uniq only works after sort if duplicates are not already grouped.

Gzip exists: data dumps often end in .gz. gunzip -c file.gz | head peeks without fully unpacking. We will not require gzip in this lesson.

Practice on your machine

cd ~/dcubes/linux-lab
ls data/movies.csv
head -n 5 data/movies.csv
wc -l data/movies.csv

What you should see: a header line title,year,genre,minutes, then movie rows. Line count is 21 if the file has 1 header + 20 movies.

List genres (skip the header with tail):

cut -d, -f3 data/movies.csv | tail -n +2

tail -n +2 means “from line 2 to the end.”

Count unique genres:

cut -d, -f3 data/movies.csv | tail -n +2 | sort | uniq -c | sort -nr

What you should see: counts, highest first. Sci-Fi and Drama should appear more than once.

How many movies from 1999?

cut -d, -f2 data/movies.csv | grep 1999 | wc -l

What you should see: 2 (The Matrix and The Sixth Sense in the sample).

Common mistakes

  • Forgetting the header. wc -l is not “number of movies.” Subtract one, or use tail -n +2.
  • Commas inside titles. This sample avoids them. Real CSVs need a real parser. The shell is for a peek, not a warehouse.
  • cut without -d,. Default delimiter is a tab, so you would get whole lines.

Next

You have enough for the First data shift demo. Lessons 10–13 add env vars, disk, installs, and SSH — take them before or after the demo.