cut, sort -u & tail -n +2

Work with columns

Lesson 13 of 20 · 10 min · Module 4: Find and organize

CSV files and logs are tables made of text. A few commands let you pick, filter, and sort their columns.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Pick columns with cut
  • Skip a header row
  • Sort and remove duplicates

The idea

cut -d, -f1 splits each line at commas and keeps field 1. -f1,3 keeps fields 1 and 3. tail -n +2 starts at line 2, skipping a header row. sort -u sorts and removes duplicate lines in one step.

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

01Choose the delimiter

-d sets the character between columns, here a comma. -f picks the fields by position, counting from 1.

cut -d, -f1,4 data/servers.csv | head -n 3
Output
name,city
web-01,Bucharest
web-02,Cluj

02Filter rows, then pick columns

grep keeps the rows you want and cut keeps the columns you want. Together they behave like a tiny database query.

03Skip the header

tail -n +2 means "from line 2 to the end". Without it, the word role from the header would appear in your list of roles.

Your turn

Using data/servers.csv (columns: name, ip, role, city): 1) show the names of the servers in Bucharest, one per line; 2) show each role once, sorted alphabetically, without the header.

What the checks look for

  • Shows web-01, db-01 and web-03
  • Shows cache, database, web once each without the header
Try it in the editor →

Take this with you

grep picks rows, cut picks columns, sort -u keeps one of each.

Go a little further

Count how many servers each city has with cut, sort, and uniq -c.

Learn Linux Command Line for free

20 short lessons with real code and instant checks.

See the whole course →