Script Valley
Linux & Bash for Developers
Text Processing & Searching/Assessment

Practice & Assessment

Test your understanding of Text Processing & Searching

Multiple Choice Questions

5
1

What does the command `grep -v "200" access.log` output?

2

What is the effect of `command > file.txt 2>&1`?

3

Which sed command removes all blank lines from a file in-place?

4

In awk, what does `$NF` refer to?

5

What does `tail -f /var/log/nginx/access.log` do?

Coding Challenges

1
1

Log Analyzer Pipeline

Given a web server access log at /var/log/nginx/access.log (or generate a sample with 50 lines using a loop), build a single-line pipeline that: (1) extracts only HTTP 500 errors using grep, (2) counts the unique IP addresses that caused them using awk to print $1, then sort and uniq -c, (3) sorts by frequency descending using sort -rn, (4) shows the top 5 offenders using head -5, (5) saves the result to ~/reports/top_500_ips.txt using tee. Expected output: a file with up to 5 lines each showing a count and IP address, e.g. '12 192.168.1.5'. Time estimate: 20 minutes.

Medium

Mini Project

1

Automated Log Summary Generator

Write a sequence of terminal commands (using pipes, grep, awk, sed, head, tail, wc, and redirections) that processes /var/log/syslog or any available log file and produces a summary report at ~/log_summary.txt. The report must include: (1) Total line count of the log, (2) Count of WARNING lines, (3) Count of ERROR lines, (4) The 10 most recent entries, (5) Top 5 most common words in error lines (using grep + tr + sort + uniq). Use >> to append each section with a section header added via echo. The final file should be human-readable with labeled sections. No shell scripts — pure terminal commands only.

Medium