Skip to content
The Chat Archive
o3-2025-04-16· OpenAI LMArena Human Preference 140K

I have a few Markdown files in a directory. Each file has YAML frontmatter. I'd like to…

  1. 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".

  2. Assistant

    Here’s a quick one-liner (plus a tiny loop) you can paste into any POSIX-ish shell.
    It will:

    1. Read every *.md file in the current directory
    2. Strip the YAML front-matter (everything from the first --- to the next ---)
    3. Replace it with exactly a blank line, three asterisks, and another blank line (\n***\n)
    4. 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"
    done
    

    Want to edit the files in-place? Add -i to Perl:

    for f in *.md; do
      perl -0777 -pi -e 's/\A---.*?\n---\s*/\n***\n/s' "$f"
    done
    

    How it works

    • perl -0777 -p Slurps 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---/s Matches 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 -z or -E sed options differ between BSD/GNU.)

    That’s it—run, copy-paste, or adapt as you like!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.