Merge multiple Markdown files into one stream
Goal: Concatenate several files, with the source path visible before each one, to review a set of docs in one pass.
Prerequisites: None.
Query
$ mq -S 's"\n${__FILE__}\n"' 'identity' docs/**/*.md
Input
docs/intro.md:
# Introduction
Welcome.
docs/usage.md:
# Usage
Use it like this.
Output
docs/intro.md
# Introduction
Welcome.
docs/usage.md
# Usage
Use it like this.
Notes
-S <query>inserts the result of<query>as a separator between files;__FILE__is a built-in variable holding the current file’s path.identitypasses each node through unchanged, swap it for a real query to filter/transform while merging.- This runs the query once per file and stitches the results together with
-S. To instead run one query across all files at once, e.g. to count something over the whole set, use--eval-all. It has no per-file separator, so it’s for aggregation, not this kind of readable concatenation.