Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the first word of the line.
Bash Scripting
echo "Hello world" | cut -d ' ' -f [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as field number causes no output.
Using 2 or 3 extracts the second or third word, not the first.
✗ Incorrect
The cut command with -f 1 extracts the first field (word) separated by space.
2fill in blank
mediumComplete the code to count lines containing the word 'error'.
Bash Scripting
grep 'error' logfile.txt | wc -l > [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a log file name may confuse output with input.
Not redirecting output causes no file to be created.
✗ Incorrect
Redirecting output to count.txt saves the number of lines with 'error'.
3fill in blank
hardFix the error in the code to replace 'foo' with 'bar' in file.txt.
Bash Scripting
sed -i 's/[1]/bar/g' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'foo' and 'bar' reverses the replacement.
Using unrelated words causes no change.
✗ Incorrect
The sed command replaces 'foo' with 'bar', so 'foo' must be the search pattern.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 letters.
Bash Scripting
declare -A lengths for word in apple banana cat dog; do if [[ ${#word} [1] 3 ]]; then lengths[[2]]=${#word} fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > reverses the condition.
Using len instead of word as key causes errors.
✗ Incorrect
We check if word length is greater than 3 and use the word as the key in the dictionary.
5fill in blank
hardFill all three blanks to filter lines containing 'error' and count unique occurrences.
Bash Scripting
grep [1] logfile.txt | sort | uniq -c | sort [2] -k1,1 | head -n [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -r instead of -nr sorts incorrectly.
Not limiting head to 5 lines shows too many results.
✗ Incorrect
We grep 'error', sort uniquely counting occurrences, sort numerically reverse, and show top 5.