I have a few Markdown files in a directory. Each file has YAML frontmatter. I'd like to…
- User
I have a few Markdown files in a directory. Each file has YAML frontmatter. I'd like to print the content of all files, but replace the markdown frontmatter with "\n***\n".
- Assistant
Here’s a quick one-liner (plus a tiny loop) you can paste into any POSIX-ish shell.
It will:- Read every *.md file in the current directory
- Strip the YAML front-matter (everything from the first --- to the next ---)
- Replace it with exactly a blank line, three asterisks, and another blank line (
\n***\n) - Dump the result to STDOUT (nothing is modified on disk unless you add -i)
# Bash / Z-sh / fish (posix) — prints each file after the replacement for f in *.md; do perl -0777 -pe 's/\A---.*?\n---\s*/\n***\n/s' "$f" doneWant to edit the files in-place? Add
-ito Perl:for f in *.md; do perl -0777 -pi -e 's/\A---.*?\n---\s*/\n***\n/s' "$f" doneHow it works
•
perl -0777 -pSlurps the entire file (‐0777) and prints it (‐p) after running the regex.
•-i(optional) Edits files in place instead of just printing to STDOUT.
•/^---.*?\n---/sMatches from the very first --- to the next --- (non-greedy, dot matches newlines).
•'\n***\n'Replacement text.Alternative pure-bash (GNU sed) version
for f in *.md; do sed -e '1,/^---$/d' "$f" | # drop everything through 2nd --- sed '1i\'$'\n''***'$'\n' # prepend \n***\n to what’s left done(The Perl version is more portable because the
-zor-Esed options differ between BSD/GNU.)That’s it—run, copy-paste, or adapt as you like!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.