Challenge - 5 Problems
CSV Processing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Extract the second column from a CSV file
Given a CSV file
Which command outputs only the age column values (excluding the header)?
data.csv with the following content:name,age,city Alice,30,New York Bob,25,Los Angeles Carol,27,Chicago
Which command outputs only the age column values (excluding the header)?
Attempts:
2 left
💡 Hint
Use a command to skip the header line, then extract the second column.
✗ Incorrect
Option A skips the first line (header) using
tail -n +2 and then extracts the second column with cut -d',' -f2. Option A includes the header. Option A prints the header too. Option A extracts the third column, not the second.💻 Command Output
intermediate2:00remaining
Count rows where the city is 'Chicago'
Using the same
data.csv file, which command outputs the number of rows where the city is exactly Chicago?Attempts:
2 left
💡 Hint
Use a tool that can compare exact field values.
✗ Incorrect
Option C uses awk to check if the third field equals 'Chicago' exactly and counts matches. Option C matches lines ending with Chicago but includes header if it matches. Option C counts any line with 'Chicago' anywhere, including header. Option C counts lines containing 'Chicago' but includes header if present.
🔧 Debug
advanced2:00remaining
Fix the script to sum ages from CSV
This script aims to sum all ages from
What is the main reason this script does not produce the correct sum?
data.csv (excluding header):total=0 while IFS=',' read name age city; do total=$((total + age)) done < data.csv echo $total
What is the main reason this script does not produce the correct sum?
Bash Scripting
total=0 while IFS=',' read name age city; do total=$((total + age)) done < data.csv echo $total
Attempts:
2 left
💡 Hint
Check if the header line is processed as data.
✗ Incorrect
The script reads the header line 'name,age,city' and tries to add 'age' (a string) to total, causing an error or wrong result. Skipping the header fixes this.
🚀 Application
advanced2:00remaining
Extract unique cities sorted alphabetically
Which command pipeline extracts all unique city names from
data.csv (excluding header) and sorts them alphabetically?Attempts:
2 left
💡 Hint
Skip the header, extract the third column, then sort and remove duplicates.
✗ Incorrect
Option D uses awk to skip the header (NR>1), prints the third field, sorts, and removes duplicates with uniq. Option D works but uniq after sort is less efficient than sort -u. Option D includes header. Option D sorts in reverse order, not alphabetical.
🧠 Conceptual
expert2:00remaining
Why is parsing CSV with simple tools risky?
Why can using basic tools like
cut or awk with a comma delimiter be unreliable for processing CSV files?Attempts:
2 left
💡 Hint
Think about how commas inside quotes affect splitting.
✗ Incorrect
CSV fields may contain commas inside quotes, so splitting by commas blindly breaks fields. Proper CSV parsers handle quoted fields correctly. Options A, B, and D are incorrect statements.