PDA

View Full Version : He sed WHAT?!



Ben
September 4th, 2007, 23:05
Earlier I was attempting to learn how to use SED, and I came across a problem.

OK, say I was trying to edit blahblah.html, and change all the <blockquote>'s to <tt>'s. Here's the command I tried ...


sed -e 's/blockquote/tt' blahblah.html > blahblah2.html

Yet it did not work. It just spat out the original.

I tried some variations:


sed -e '/*/ s/blockquote/tt /*/' blahblah.html > blahblah2.html

But sed just threw empty beer bottles at me.

Help?

notnamed
September 5th, 2007, 01:33
sed -e 's/blockquote/tt/' blahblah.html >> blahblah2.html

I don't know why this worked, because I've never even heard of sed, regex makes about as much sense as obfuscated Perl, and command line switches make me cry sometimes, but there you go. WFM.

Ben
September 5th, 2007, 07:05
That got half of it done ...

As in it changed all the <blockquote>s to <tt>s but not </blockquote>s to </tt>s. But if I do it twice does the other half. I remember there being an option where it only does one change per line, that's probably it. I'll look it up later.

Thanks, though, notnamed.

notnamed
September 5th, 2007, 11:23
sed 's/blockquote/tt/g' blahblah.html > blahblah2.html

Got that from the one-liners tutorial here (http://sed.sourceforge.net/grabbag/tutorials/), looks like a pretty good resource.

Ben
September 5th, 2007, 16:58
Wow, I feel stupid.

Thank you, NN.

notnamed
September 5th, 2007, 17:16
No problem. Google loves you. And know I, too, know how to use Sed. Awesome.