0
0
Bash Scriptingscripting~20 mins

Why scripts often process text in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Text Processing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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}'
Abanana
Bapple banana
Capple
Dcherry
Attempts:
2 left
💡 Hint
The awk command prints the second word from the input line.
🧠 Conceptual
intermediate
2:00remaining
Why do scripts often use text processing tools?
Why do many scripts use tools like grep, awk, and sed to process text?
ABecause scripts cannot handle binary data at all.
BBecause text is a universal format that is easy to read and manipulate in scripts.
CBecause text processing tools are faster than compiled programs.
DBecause scripts only work with files that have .txt extension.
Attempts:
2 left
💡 Hint
Think about why text is common in data exchange and logs.
📝 Syntax
advanced
2: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?
Aawk -F ',' '{print $1}' file.csv
Bcut -f 1 file.csv
Csed 's/,.*//' file.csv
Dcut -d ',' -f 1 file.csv
Attempts:
2 left
💡 Hint
The delimiter for CSV is a comma, so specify it explicitly.
🔧 Debug
advanced
2: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"
AThe cut command uses the wrong delimiter.
BThe variable line is not quoted in the echo command.
CThe extracted username has a leading space that is not trimmed.
DThe script is missing a shebang line.
Attempts:
2 left
💡 Hint
Look carefully at the output and spaces after the colon.
🚀 Application
expert
2: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?
A3
B10
C1
D0
Attempts:
2 left
💡 Hint
uniq outputs only unique lines after sorting.