Challenge - 5 Problems
Text Processing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this text processing command?
Consider the following bash command that processes text. What will it output?
Bash Scripting
echo "apple banana cherry" | awk '{print $2}'
Attempts:
2 left
💡 Hint
The awk command prints the second word from the input line.
✗ Incorrect
The echo command outputs a line with three words. Awk splits the line by spaces and prints the second word, which is 'banana'.
🧠 Conceptual
intermediate2:00remaining
Why do scripts often use text processing tools?
Why do many scripts use tools like grep, awk, and sed to process text?
Attempts:
2 left
💡 Hint
Think about why text is common in data exchange and logs.
✗ Incorrect
Text is a simple, universal format that scripts can easily read, search, and modify using standard tools. This makes automation easier and more flexible.
📝 Syntax
advanced2:00remaining
Which command correctly extracts the first column from a CSV file?
Given a CSV file with comma-separated values, which bash command correctly extracts the first column?
Attempts:
2 left
💡 Hint
The delimiter for CSV is a comma, so specify it explicitly.
✗ Incorrect
The cut command with -d ',' sets the delimiter to comma and -f 1 extracts the first field. Option D splits on whitespace by default (unless -F is specified), Option D uses default delimiter (tab), and Option D removes everything after first comma but may not handle all lines correctly.
🔧 Debug
advanced2:00remaining
Why does this script fail to extract the username?
This bash script tries to extract the username from the line 'user: alice' but fails. Why?
SCRIPT:
line='user: alice'
username=$(echo $line | cut -d ':' -f 2)
echo "$username"
Attempts:
2 left
💡 Hint
Look carefully at the output and spaces after the colon.
✗ Incorrect
The cut command extracts the part after the colon, but it includes the space before 'alice'. This space is part of the output and may cause issues if not trimmed.
🚀 Application
expert2:00remaining
How many lines will this script output?
This bash script filters lines containing 'error' from a log file and counts unique error types.
SCRIPT:
cat logfile.txt | grep 'error' | cut -d ':' -f 2 | sort | uniq
If logfile.txt contains 10 lines with 'error', but 3 unique error types, how many lines will the script output?
Attempts:
2 left
💡 Hint
uniq outputs only unique lines after sorting.
✗ Incorrect
The script extracts the error type from each line, sorts them, and uniq filters duplicates. So the output lines equal the number of unique error types, which is 3.