Borys Bradel's Blog
Sed to the rescue
Tags: sed, programming June 4, 2008
I realized that I made a typo in my program to generate blogs, accidentally reversing opening and closing paragraph tags. Since I didn't want to regenerate everything, I looked at how to get sed, which is a line editor utility, to modify the files.
The first stop was a list of sed one liners. One of them is "sed 's/foo/bar/'", which replaces the first instance of foo with bar on all lines.
Next up was trying to figure out how to modify files in place. The answer was found here. The answer is to use "sed -i -e 'expression' files".
Perfect for what I need. Then I ran the following script and the html files are fixed.
sed -i -e 's/<P><\/P>/<\/P><P>/' *.*
The rss 2.0 feed is left as is though. That's okay because it will be updated the next time that an entry is posted (i.e. this one).
Copyright © 2008 Borys Bradel. All rights reserved. This post is only my possibly incorrect opinion.