Remove first line from all files in a vault?

Things I have tried

Apologies if this is a new user question with an obvious solution, but I searched online and through the forums and couldn’t find the answer. I tried seeing if the Refactor plugin could solve the problem, but I couldn’t without creating other problems.

What I’m trying to do

I’m bringing in a bunch of .md files that have a first line with a # that matches the file name (so if the file name is “Note About Unicorns” then the imported page in Obsidian shows that as the file name and then, right below it “# Note About Unicorns”.)

I’m trying to get rid of the opening line on every file I’ve imported so that, when looking at that page, I don’t get the double page name effect.

Is there a simple workaround to deal with this?

No simple workaround besides turning of the show title option…

If you contemplate on doing such a change, remember to account for the frontmatter if you have that in any of your files, so that you don’t mess up those by blindly removing the first line in every file.

I don’t think there is anything within Obsidian that can do this for you. You will need a script that ingests all your files, removes the first line and outputs the result. If you are somewhat familiar with code, you can use this solution python - Quickly remove first n lines from many text files - Stack Overflow Just change the xrange line to 1, or whatever number of lines at the beginning you need removed, and change the file extension and you should be good to go.

That’s what I was beginning to suspect. Thanks for the confirmation. I might give the solution you suggested a try, but I’m hoping maybe there’s a suitably easy-to-use text parsing app out there that might serve the purpose so that I can avoid having to run python scripts.

Do you have any files with frontmatter in them?

If not, it’s not that hard to do using something like VS Code.

It’s possible with frontmatter, as well, but it’s just a little trickier.

Yeah this is trivial with the command line. You can actually ask ChatGPT to write the script for you if that’s easier.

For me, I wanted to remove the first 4 lines from every note in my vault. The below prints from line 5 onwards to a temp file, then replaces the original with this temp. And so on for every md file in the directory I’m running it in.

for file in *.md; do tail -n +5 "$file" > "$file.tmp" && mv -f "$file.tmp" "$file"; done

WARNING: this is a destructive change, so back up your vault first just in case something goes wrong.

Sorry, just double-checking. Did you notice holroy’s first reply to you? You can also simply turn off the inline title display in the Obsidian settings. I’m not sure if that suits you or not.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.