Practice & Assessment
Test your understanding of Text Processing and File Operations
Multiple Choice Questions
5Which command should you use to sum all values in the first column of a whitespace-separated file?
What does `${path##*/}` return when `path=/home/alice/file.txt`?
Why should you use `-print0` with `find` and `-0` with `xargs`?
In Bash regex matching, why should you store the pattern in a variable instead of quoting it inline?
What does `flock -n 9` do in a Bash script?
Coding Challenges
1Log Report Generator
Write `report.sh` that accepts a directory of `.log` files as `$1` and an output file as `$2`. Use `find` to locate all `.log` files. For each file: use `grep` and `awk` to count ERROR, WARN, and INFO lines; output a CSV row: `filename,error_count,warn_count,info_count`. At the end, append a totals row summing each column using `awk`. Use `mktemp` for intermediate files and clean up with `trap`. Handle the case where no log files exist. Input: log directory path, output CSV path. Output: CSV file with header, one row per file, one totals row. Time estimate: 25-30 minutes.
Mini Project
Config File Manager
Build `config-manager.sh` with subcommands: `get KEY FILE`, `set KEY VALUE FILE`, `delete KEY FILE`, `list FILE`, and `validate FILE SCHEMA`. The config format is `KEY=VALUE` (shell-style env file). `get` uses parameter expansion and grep. `set` uses sed for in-place updates, appending if key doesn't exist. `delete` uses sed to remove the line. `list` uses awk to format as a table. `validate` reads a schema file (one KEY per line, optionally KEY=REGEX) and checks that required keys exist and match their regex using Bash `=~`. Use `flock` to prevent concurrent writes. Write output to stdout, errors to stderr.
