Lines and streams
Linux text tools treat a file as a list of lines. Our file, scores.txt, has 4 lines. Each line holds a name, a score and a result, separated by spaces. The job: list everyone who must retry.
We type one command made of three programs joined by |, the pipe symbol. A line that ends in | is not finished, so bash shows its second prompt, >, and waits for the rest.
Every program starts with three streams: standard input (stdin) to read text, standard output (stdout) to write results, and standard error for problems. Alone, a program reads the keyboard and writes to the terminal.
A pipe joins one program's stdout to the next one's stdin. bash starts grep, sed and awk together. Between each pair the kernel keeps a small buffer, usually 64 KiB, so lines flow straight through without a file in between.
grep, then sed
grep was given a file name, so it reads scores.txt itself, one line at a time. Its first word, fail, is the pattern: the text it looks for in every line.
grep keeps a line only if it contains the pattern. ana and cy passed, so their lines are dropped. "ben 3 fail" and "dee 4 fail" go out through stdout, into the pipe, to sed.
sed is the stream editor: it changes text as it flows past. The rule s/fail/retry/ means substitute: on each line, replace the first fail with retry. "ben 3 fail" becomes "ben 3 retry".
awk and the answer
awk reads each line from the second pipe and splits it into fields at the spaces: $1 is the first word, $2 the second, $3 the third. For "ben 3 retry", $1 is ben, $2 is 3, $3 is retry.
The part in braces runs once for every line. print $1, $3 prints the first and the third field with one space between. "ben 3 retry" becomes "ben retry", then "dee 4 retry" becomes "dee retry".
awk's stdout is not piped anywhere, so its lines appear in the terminal: ben retry and dee retry. scores.txt itself is unchanged: sed edited the stream of text, not the file.
What happens
;; step 1/10 · lines scores.txt 4 lines, one person per line line 1 ana 7 pass line 2 ben 3 fail line 3 cy 9 pass line 4 dee 4 fail each line name score result goal who failed, and must retry?
Without the g flag (s/fail/retry/g), sed replaces only the first match on each line. Careful: sed -i writes the change back into the file and overwrites it, so try the command without -i first and keep a copy. A pipe carries stdout only. Error messages go to stderr, which still reaches the terminal, so you see them even in the middle of a pipeline.