Script Valley
Bash Scripting for Developers
Text Processing and File Operations/Assessment

Practice & Assessment

Test your understanding of Text Processing and File Operations

Multiple Choice Questions

5
1

Which command should you use to sum all values in the first column of a whitespace-separated file?

2

What does `${path##*/}` return when `path=/home/alice/file.txt`?

3

Why should you use `-print0` with `find` and `-0` with `xargs`?

4

In Bash regex matching, why should you store the pattern in a variable instead of quoting it inline?

5

What does `flock -n 9` do in a Bash script?

Coding Challenges

1
1

Log 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.

Medium

Mini Project

1

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.

Hard
Practice & Assessment โ€” Text Processing and File Operations โ€” Bash Scripting for Developers โ€” Script Valley โ€” Script Valley