LPIC-1 103.2: Processing text with filters
Counting with cut, sort and uniq, spotting Windows line endings,
splitting and joining files, and following a log.
Before you start
The lab creates /root/filters/ with three text files, report1.txt,
report2.txt and report3.txt; one of them has Windows line endings.
Work as root (sudo -i), and write answers to the files in
/root/lab-answers/. Where the journal is kept only in memory (no
/var/log/journal), a reboot loses task 5's message, so check before
you reboot.
Tasks
-
Make
/root/filters/fruit.txtwith the five lines from the chapter:apple 3 banana 12 cherry 7 apple 5 banana 1Count how many lines mention each fruit with
cut,sortanduniq -c, and write the output to/root/lab-answers/1. -
Count the accounts using each login shell in
/etc/passwd, most common first, and write the output to/root/lab-answers/2. -
Use
od -cto find out which of the three report files uses Windows line endings (\r \n), and write its name to/root/lab-answers/3. -
Split a large file from
/var/loginto 100-line pieces in/root/filters/split/, join them back withcatinto/root/filters/joined.log, and prove the result is identical withsha256sum. -
Follow
/var/log/syslogor/var/log/messageswithtail -fin one terminal while runninglogger helloin another. If neither file exists, your system logs only to the journal: usejournalctl -finstead.
Hints
cut -d' ' -f1 FILE | sort | uniq -c.cut -d: -f7, thensort | uniq -c | sort -rn.od -c FILE | head;filesays "with CRLF line terminators" too.split -l 100 FILE /root/filters/split/part-,cat .../part-* > ...,sha256sum. Pick a file that doesn't change while you work, such ascloud-init.logor an older rotated log.logger hello;journalctl -forjournalctl -t USER.