# Answer questions about a log file with a pipeline

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/log-pipeline-full-en
A pipeline turns raw log lines into counts by extracting fields, sorting and counting. The access log is synthetic; its numbers are not traffic data.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-48-A, TE-48-B and TE-48-C. The expected non-zero exit is TE-48-C (exit status 2). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-48-A: a log pipeline over a synthetic file returns the counts that the synthetic data implies

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'GET /a 200\nGET /b 200\nPOST /a 500\nGET /a 200\n' > access.log
```

Command:

```bash
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -2; echo codes=$(awk '{print $3}' access.log | sort -u | tr '\n' ' ')
```

Recorded output:

```
      3 GET
      1 POST
codes=200 500
```

### TE-48-B: awk with a field test and grep -c count the lines with status 500 and with status 200

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'GET /a 200\nGET /b 200\nPOST /a 500\nGET /a 200\n' > access.log
```

Command:

```bash
awk '$3==500' access.log | wc -l; grep -c ' 200$' access.log
```

Recorded output:

```
1
3
```

Exit status: 0. This status and the output match what was written before the run.

### TE-48-C: expected non-zero exit: grep -c on a log file that does not exist exits with status 2

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'GET /a 200\nGET /b 200\nPOST /a 500\nGET /a 200\n' > access.log
```

Command:

```bash
grep -c 200 missing.log
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
grep: missing.log: No such file or directory
```

Exit status: 2. This status and the output match what was written before the run.

TE-48-B: by the setup, one line has status 500 and three lines end in 200. awk printed a count of 1 for the 500 line, and grep -c printed 3. TE-48-C: grep -c 200 missing.log exited with status 2, nothing was printed to standard output, and standard error reads grep: missing.log: No such file or directory.

## Limits

The access log is synthetic; its numbers are not traffic data.

## Source

Source: https://www.gnu.org/software/gawk/manual/

## Evidence

- `TE-48-A`: a log pipeline over a synthetic file returns the counts that the synthetic data implies

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-48-A` | a log pipeline over a synthetic file returns the counts that the synthetic data implies | 0 | PASS | `f5bf7ca04ee9` |
| `TE-48-B` | awk with a field test and grep -c count the lines with status 500 and with status 200 | 0 | PASS | `af6dd763e790` |
| `TE-48-C` | expected non-zero exit: grep -c on a log file that does not exist exits with status 2 | 2 | PASS | `1bc665b56f1c` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Bash conditionals: [ ] and [[ ]] with an empty variable](https://kairos-2z6s.onrender.com/res/bash-conditionals-full-en)
- [mkdir, cp, mv and rm: the basic file commands](https://kairos-2z6s.onrender.com/res/file-commands-full-en)
- [grep: search text, with the options worth knowing](https://kairos-2z6s.onrender.com/res/grep-basics-full-en)
- [tar basics: pack, list and unpack a folder](https://kairos-2z6s.onrender.com/res/tar-basics-full-en)
- [Git Merge vs Rebase: How Each Integrates Changes and Shapes History](https://kairos-2z6s.onrender.com/res/merge-vs-rebase-full-en)
- [Leaked API key: revoke first, then scan history](https://kairos-2z6s.onrender.com/res/leaked-key-revoke-and-scan-en)
- [Pipes and redirection: where command output goes](https://kairos-2z6s.onrender.com/res/pipes-redirection-full-en)
