Practice: Reading and Editing Text
On this page
A teammate gives you a log and two unfinished handoff files. Before returning them, you need to inspect the log, watch a completion message arrive, and save the note and configuration with the agreed status. Two supporting text files also need a format explanation.
This practice combines all five B07 lessons. Documentation and earlier lessons are allowed; the evidence matters more than memorizing keys.
Before you start
Section titled “Before you start”Finish Viewing short and long files through Text format surprises (B07.1–B07.5). The editor task uses the course VM’s vi, which runs Vim-tiny, as established in B07.4. If that tested editor is absent from your system, defer its goal until B12 rather than substituting an unverified program.
Keep your existing B04 practice directory. Use only disposable ~/lab/b07/practice; all earlier B07 directories remain outside it. Run this setup once, or use Reset this lesson before repeating it.
mkdir -p ~/lab/b07/practicecd ~/lab/b07/practiceprintf 'Line %02d: routine check\n' {1..39} > handoff.logprintf 'Line 40: CHECKPOINT reached\n' >> handoff.logprintf 'Line %02d: routine check\n' {41..80} >> handoff.logprintf 'Inspection pending\n' > handoff.txtprintf 'status=draft\n' > handoff.confprintf 'Handoff begins\n' > events.logprintf 'name\tvalue\n' > columns.txtprintf 'café\r\n' > received.txtThese lines build the handoff on your VM; you do not need to download a fixture. The log has numbered entries and a checkpoint. The note and configuration begin unfinished. The final two files contain spacing and encoding details for inspection. Copy the setup exactly, including the accented character and escape sequences introduced in B07.5.
Your task
Section titled “Your task”Reach these five goals, in order:
- You have read the first and last two entries of
handoff.log, found its checkpoint in a pager with line numbers, and returned to Bash. You can state the log’s newline count and the checkpoint’s line number without printing the whole log. - You have watched
events.logfrom a second terminal while the first appendshandoff: reviewed. You have stopped watching deliberately and verified that both saved lines remain. Both terminals use~/lab/b07/practice. - Nano has saved
handoff.txtwith the single lineInspection complete. It ends with one newline and no extra blank line. You have verified the saved result after leaving Nano. - Vim-tiny, launched as
vi handoff.conf, has changed only thedraftvalue toready. You used a search to locate it, saved, exited, and read the result from Bash. - You can identify the encoding and line ending of
received.txt, explain its different byte and character counts, and identify whethercolumns.txtcontains a tab or ordinary spaces between its words. Preserve both files.
Expected evidence
Section titled “Expected evidence”Your terminal and explanations establish:
- The two boundary pairs, a pager search result, and the log count.
- A completion line arriving while the watcher is running, then a returned prompt after interruption and a read of the saved file.
- A saved one-line Nano note, with exactly one end marker when inspected using B07.5’s diagnostic view.
- A saved configuration with
status=ready, produced throughvirather than by rewriting it with a shell command. - A file identification, a stored-byte view, separate byte/character counts, and visible whitespace evidence for the supporting files.
The editor results in the solution were captured on the course VM. The noninteractive inspection and reset evidence comes from the Ubuntu lab. No full-screen program is simulated as a replay.
Hint for goal 1
Use head and tail for boundaries. In less -N, the forward search begins with a slash and q returns to Bash. wc -l counts newline characters.
Hint for goal 2
Run tail -f in the window you will leave watching. In the other, use B07.2’s exact echo 'message' >> file pattern. Ctrl+C belongs in the watcher window.
Hint for goal 3
Nano’s Ctrl+K cuts the current line. Starting from the single original line, one cut is enough. Type its replacement without adding an extra Enter; confirm the saved ending with cat -A.
Hint for goal 4
From Normal mode, a search positions the cursor on draft. cw changes the word and enters Insert. Esc returns before the save command.
Hint for goal 5
file identifies the text, od -c exposes stored controls, and wc -c differs from wc -m. cat -A distinguishes a tab from a gap made of spaces.
Solution
Section titled “Solution”Solution
Goal 1: inspect without flooding the terminal
cd ~/lab/b07/practicehead -n 2 handoff.logLine 01: routine checkLine 02: routine checktail -n 2 handoff.logLine 79: routine checkLine 80: routine checkwc -l handoff.log80 handoff.logless -N handoff.logType /CHECKPOINT, Enter. The checkpoint is on line 40, as in the fixture inspected in B07.1. Press q to return. The file has 80 newlines; reading did not change them.
Goal 2: observe, interrupt, then inspect
In the right terminal:
cd ~/lab/b07/practicetail -f events.logIn the left terminal:
cd ~/lab/b07/practiceecho 'handoff: reviewed' >> events.logCopy the append line as it is; >> adds a line to the end of the file, and B09 explains it. The right terminal receives the appended line. It stays occupied by the watcher until you press Ctrl+C there.
After stopping it, run pwd to check that Bash accepts a command again, then read the file:
pwd/home/learner/lab/b07/practicecat events.logHandoff beginshandoff: reviewedThe two-window method is the one shown in B07.2’s screenshots. The saved-file output above is the lab’s actual read after the same append command, not a recording of two concurrent terminals.
Goal 3: save the single-line Nano note
nano handoff.txtStarting from the original Inspection pending line:
- Press Ctrl+K once to cut that line.
- Type
Inspection completewithout pressing Enter. - Press Ctrl+O, Enter, then Ctrl+X.
cat -A handoff.txtInspection complete$This output was captured on the course VM. One $ marks the final newline. A second line containing only $ would reveal an unwanted blank line. The shown marker is diagnostic notation, not part of the note.
Goal 4: change the configuration in vi
vi handoff.conf- Press Esc, then type
1G. - Type
/draft, Enter. - Type
cw, thenready, then Esc. - Type
:w, Enter, then:q, Enter.
cat handoff.confstatus=readyThis saved result was captured on the course VM. If you lose track of the mode, Esc returns from Insert before an editor command. Do not type a shell command into the file to inspect it.
Goal 5: describe stored text rather than appearance
file received.txtreceived.txt: Unicode text, UTF-8 text, with CRLF line terminatorsod -c received.txt0000000 c a f 303 251 \r \n0000007wc -c received.txt7 received.txtwc -m received.txt6 received.txtcat -A columns.txtname^Ivalue$received.txt contains UTF-8 text and CRLF. The accented character uses two bytes; carriage return and newline each count as characters too. It therefore has seven bytes and six characters. columns.txt contains a tab, represented by ^I, rather than four stored spaces.
Recall check
Section titled “Recall check”Answer without running anything, then open each answer.
1. Which tool would you choose to search a long file while keeping it open? Which two tools would you use to read only its beginning and end?
Answer
Use less for paging and searching; -N adds line numbers. Use head for the beginning and tail for the end, with -n to choose the count.
2. A watcher prints nothing for a while and has no Bash prompt. Does that prove the shell is stuck? Where do you type an append command?
Answer
No. tail -f may be waiting for additions. Type the append command in the other terminal, which has a prompt and addresses the same file. Ctrl+C in the watcher stops it and returns control to Bash.
3. In Nano, does an asterisk mean the file is already saved? What do Ctrl+O and Ctrl+X do?
Answer
The asterisk marks unsaved buffer changes. Ctrl+O writes the buffer to the chosen filename; Enter accepts that filename. Ctrl+X exits, asking about remaining unsaved changes when needed.
4. In this VM’s vi, what changes the meaning of an ordinary letter key? How do you save after typing a replacement word?
Answer
The mode changes its meaning. Normal interprets editing keys, while Insert adds file text. Press Esc to return from Insert, then type :w, Enter. Use :q, Enter, to exit afterward; E37 means unsaved changes remain.
5. Does a wider-looking gap prove that a file contains more spaces? What do ^I and ^M$ mean in these cat -A inspections?
Answer
No. A tab advances to a tab stop and can resemble several spaces. ^I represents a tab. ^M$ represents a carriage return followed by a newline. These are display markers, not literal text added to the file.
6. Can a UTF-8 byte count exceed its character count? Can a file with visible text have a zero result from wc -l?
Answer
Yes to both. Some UTF-8 characters occupy multiple bytes. wc -l counts newline characters, so visible text without a final newline can have a zero newline count.
Reset this lesson
Section titled “Reset this lesson”Stop any watcher with Ctrl+C and close the practice editors deliberately. Inspect only this practice directory from its parent:
cd ~/lab/b07ls -AR practiceIt contains columns.txt, events.log, handoff.conf, handoff.log, handoff.txt, and received.txt. Editing their contents did not change those names.
rm -r ~/lab/b07/practiceRerun Before you start to restore the pending note, draft configuration, original log, and supporting files. If the directory is absent, skip removal. Both editor goals must then be performed again to reach the completed handoff.
- Choose a reader for the task: complete short text, selected boundaries, or a searchable long file.
- Follow additions in one terminal, append from another, and interrupt deliberately.
- Save and exit each editor using its own controls, then verify from Bash.
- Inspect line endings, encoding, and whitespace before explaining a text difference.
Next, Bash and other shells begins B08 by distinguishing shell behavior, builtins, aliases, and external programs.
Further reading
Section titled “Further reading”- On your system:
man less,man tail,man nano,man vi,man file,man od, andman wc. - GNU nano 7.2 manual and Vim first steps.
- GNU Coreutils: cat, tail, and wc.