Bloggings

Back

Sed notes: removing the end of a file after match

2025-04-10

Sed snippets

I wanted to update the footer of all the blog html files as in retrospect it wasn't great. I only use PHP on the page indexes, the blog items themselves are simple html. Find and Sed commands got this done.

In order to remove everything after PATTERN of all files:

find . -name "*.html" -print0 | xargs -0 sed -i '/PATTERN/,$d'

Add PATTERN to the bottom of all files:

find . -name "*.html" -print0 | xargs -0 sed -i '$aPATTERN'

 


ยง