Objective. Students will extract, transform, and summarize data from log and config files using grep, sed, awk, sort, uniq, and pipes.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Web servers, applications, and system services write their activity to plain-text log and configuration files. Being able to extract, transform, and summarize that text at the command line is one of the most practical skills a Linux-based developer or administrator can have. Instead of opening a 50,000-line log file in a text editor, you write a short pipeline that answers a specific question in seconds.
Linux follows the Unix philosophy: small, single-purpose tools that communicate through standard input (stdin) and standard output (stdout). The pipe character `|` connects tools so the output of one becomes the input of the next. This lets you build powerful one-liners without writing a full script.
```
command1 | command2 | command3
```
Data flows left to right through the pipeline. Nothing is written to disk unless you redirect the final output with `>` (overwrite) or `>>` (append).
`grep` scans lines of text and prints only those that match a pattern.
Regular expressions (regex) are patterns that describe sets of strings. Common metacharacters: `.` (any character), `*` (zero or more of the preceding), `^` (start of line), `$` (end of line), `[0-9]` (character class).
`sed` reads lines one at a time, applies editing commands, and writes the result to stdout. It is most commonly used for search-and-replace.
Safety note: The `-i` flag rewrites the original file permanently. Always keep a backup copy of any production configuration or log file before running an in-place substitution. A common practice is `sed -i.bak 's/old/new/g' file`, which saves the original as `file.bak` before making changes.
`awk` reads input line by line, splits each line into fields, and lets you act on specific fields. By default, fields are separated by whitespace and are referenced as `$1`, `$2`, `$3`, and so on. `$0` refers to the entire line.
Apache's combined log format places the client IP address in field 1 and the HTTP status code in field 9, which makes `awk` a natural fit for log analysis.
Combining `sort | uniq -c | sort -rn` produces a ranked frequency table — exactly what you need to find the IP addresses generating the most 404 errors.
Redirect the final output of any pipeline to a file:
```
grep "404" access.log | awk '{print $1}' | sort | uniq -c | sort -rn > top_404_ips.txt
```
Use `>>` to append to an existing file rather than overwriting it.
Every tool covered here has a manual page. Run `man grep`, `man sed`, or `man awk` to read it. Press `q` to quit. The SYNOPSIS section shows the syntax; the OPTIONS section explains each flag. Consulting the man page before guessing at a flag is a professional habit.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.
Does the school offer financial aid?
No. We don’t offer financial aid because we’re free. No, really: completely free.
Do you offer industry certification?
No. We are not certified yet, so we can’t offer that to students. What we do offer is knowledge and understanding of a trade.
Enroll first in the trade you’re interested in. You get your key, your program opens, and you begin studying.
Enroll free →