The file essay.txt contains lowercase words without punctuation, separated by spaces. Arrange the stages below so that, joined by pipes in the listed order, they print the three most frequent words in the essay, each preceded by its count.
1.
sort
2.
sort -rn
3.
tr -s ' ' '\n' < essay.txt
4.
uniq -c
5.
head -n 3
Unlock full course notes by signing up
Where warnings go in a pipeline
A build script build.sh writes progress lines such as compiled main.o to standard output and writes each warning, such as warning: unused variable, to standard error. In an interactive terminal you run ./build.sh | grep -c warning, and the script emits 3 progress lines and 5 warnings. What appears on the terminal?
Two audit copies in one pipeline
A script uses tee, a utility that copies its standard input to standard output and named files, to preserve two audit records:
All commands succeed, both output files are writable, and each letter and newline occupies one byte. The printf command writes each supplied word on its own newline-terminated line. The grep stage rejects lines beginning with oak, and tr -d '\n' deletes newline characters.
Determine the number of lines in audit.txt, the number of bytes in kept.txt, and the byte count printed by wc -c. Enter each count as an exact integer with zero decimal places.
Exit statuses with and without pipefail
In Bash on a Linux system, the directory /srv/reports does not exist. GNU ls exits with status 2 when it cannot access a path named on its command line, and grep exits with status 1 when it selects no lines. You run the two lines below once in a fresh shell and once after set -o pipefail.
Give, as whole numbers: the number that wc -l prints; the value echo prints in the fresh shell; the value echo prints with pipefail set; and the first element of the PIPESTATUS array if you read it immediately after the pipeline instead of running echo.
Redirection order changes the destination
An available program, ./report, writes exactly four newline-terminated result lines to standard output and exactly two newline-terminated warning lines to standard error. It produces no other output.
Consider four independent Bash command lines:
Before each independent run, saved.log and errors.log both exist and are empty. All commands and file operations succeed. Complete the table with the integer printed by wc -l and the number of lines in each file after that run. Enter exact integers; do not include units.