Task 02 — Count unique IPv4 addresses
Write a script 02.sh that reads an access log and prints how many distinct client IPv4 addresses appear in the first field of each line.
Submit as
02.sh
Input
| Source | Format |
|---|---|
| CLI | ./02.sh <access.log> — path to a text log file |
| Log file | One request per line. First whitespace-separated field is the client IP (nginx/Apache combined log format). Example line: |
192.168.1.1 - - [25/May/2026:09:00:01 +0000] "GET / HTTP/1.1" 200 612
| | Field 1 = 192.168.1.1. Blank lines, if any, should not break your script. |
Output
| Stream | Format |
|---|---|
| stdout | Exactly one line: a non-negative integer (the unique IP count). No extra text, labels, or blank lines. |
| stderr | Not checked |
| Exit code | 0 on success |
Example
Input file access.log:
192.168.1.1 - - [25/May/2026:09:00:01 +0000] "GET / HTTP/1.1" 200 612
10.0.0.5 - - [25/May/2026:09:00:02 +0000] "GET /api HTTP/1.1" 200 41
192.168.1.1 - - [25/May/2026:09:00:03 +0000] "GET / HTTP/1.1" 200 612
203.0.113.42 - - [25/May/2026:09:00:04 +0000] "POST /login HTTP/1.1" 302 0
stdout:
3
(Three unique IPs: 192.168.1.1, 10.0.0.5, 203.0.113.42.)
What the grader checks
Visible (4 pts) — public fixture log:
- Exit code
0(2 pt) - stdout is exactly
5(2 pt). On failure: expected5vs got
Hidden (3 pts) — separate log you do not see. Pass/fail only.
Hints
awk '{print $1}'— first column onlysort -uthenwc -l, orawkassociative array