seed: curriculum content
This commit is contained in:
39
1.solar-system/1.welcome/06.the-reader/index.md
Normal file
39
1.solar-system/1.welcome/06.the-reader/index.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Reader"
|
||||
xp: 50
|
||||
duration: 30
|
||||
difficulty: 2
|
||||
---
|
||||
|
||||
# The Reader
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, an old mission log was recovered. We need three things from it.
|
||||
>
|
||||
> When your script runs, `mission-log.txt` is sitting in the working
|
||||
> directory. Pull these out:
|
||||
>
|
||||
> 1. The first 5 lines → save to `first-five.txt`
|
||||
> 2. The last 3 lines → save to `last-three.txt`
|
||||
> 3. The total line count → save to `line-count.txt`
|
||||
>
|
||||
> Three commands:
|
||||
>
|
||||
> - `head -n N file` — first N lines
|
||||
> - `tail -n N file` — last N lines
|
||||
> - `wc -l file` — count lines
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
In `starter/starter.sh`, produce the three output files using `head`,
|
||||
`tail`, `wc`, and redirect.
|
||||
|
||||
## Objectives
|
||||
|
||||
- `first-five.txt` matches the first 5 lines of the log
|
||||
- `last-three.txt` matches the last 3 lines of the log
|
||||
- `line-count.txt` contains the line count
|
||||
13
1.solar-system/1.welcome/06.the-reader/starter/starter.sh
Normal file
13
1.solar-system/1.welcome/06.the-reader/starter/starter.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
# The Reader — pull stats from a log.
|
||||
#
|
||||
# When this script runs, mission-log.txt is in your working directory.
|
||||
# Your script must produce three files:
|
||||
#
|
||||
# - first-five.txt — the first 5 lines of mission-log.txt
|
||||
# - last-three.txt — the last 3 lines of mission-log.txt
|
||||
# - line-count.txt — the line count (output of `wc -l`)
|
||||
#
|
||||
# Tools: head, tail, wc, redirect (>)
|
||||
|
||||
# Your code here.
|
||||
39
1.solar-system/1.welcome/06.the-reader/testing/test.sh
Normal file
39
1.solar-system/1.welcome/06.the-reader/testing/test.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
cat > mission-log.txt <<'LOG'
|
||||
[1969-07-20 13:32] Apollo touchdown confirmed.
|
||||
[1969-07-20 13:33] Surface stable.
|
||||
[1969-07-20 13:34] Cabin sealed.
|
||||
[1969-07-20 13:35] EVA prep started.
|
||||
[1969-07-20 13:40] Hatch open check.
|
||||
[1969-07-20 13:42] Suit pressurization complete.
|
||||
[1969-07-20 13:50] Ladder deployed.
|
||||
[1969-07-20 13:55] First step recorded.
|
||||
[1969-07-20 14:00] Sample collection begun.
|
||||
[1969-07-20 14:10] All systems nominal.
|
||||
[1969-07-20 14:20] Communication test passed.
|
||||
[1969-07-20 14:30] Second sample box sealed.
|
||||
[1969-07-20 14:40] Solar panel deployed.
|
||||
[1969-07-20 14:50] Flag planted.
|
||||
[1969-07-20 15:00] Phone call inbound.
|
||||
[1969-07-20 15:10] Phone call complete.
|
||||
[1969-07-20 15:20] Sample box stowed.
|
||||
[1969-07-20 15:30] EVA wrap-up started.
|
||||
[1969-07-20 15:35] Hatch closed.
|
||||
[1969-07-20 15:40] Cabin re-pressurized.
|
||||
LOG
|
||||
|
||||
bash solution.sh > /dev/null 2>&1
|
||||
|
||||
N=0
|
||||
report() {
|
||||
N=$((N+1))
|
||||
if [ "$1" = "0" ]; then echo "ok $N - $2"; else echo "not ok $N - $2"; fi
|
||||
}
|
||||
|
||||
[ -f first-five.txt ]; report $? "first-five.txt exists"
|
||||
diff -q <(head -n 5 mission-log.txt) first-five.txt > /dev/null 2>&1; report $? "first-five.txt matches head -n 5"
|
||||
[ -f last-three.txt ]; report $? "last-three.txt exists"
|
||||
diff -q <(tail -n 3 mission-log.txt) last-three.txt > /dev/null 2>&1; report $? "last-three.txt matches tail -n 3"
|
||||
[ -f line-count.txt ]; report $? "line-count.txt exists"
|
||||
COUNT=$(awk '{print $1}' line-count.txt 2>/dev/null | tr -d ' ')
|
||||
[ "$COUNT" = "20" ]; report $? "line-count.txt contains 20"
|
||||
Reference in New Issue
Block a user