tags:

views:

93

answers:

2
+1  Q: 

simple SED command

I have a html report that comes out of a program we use. Its extremely plain html and id like to work on fixing it up just a bit.

What code would I need to do in sed to replace

<html>  with

<html><link rel="stylesheet" type="text/css" href="LivingInStyle.css">

Thanks, Russ

+8  A: 
sed 's/<html>/<html><link rel="stylesheet" type="text\/css" href="LivingInStyle.css">/g' file.html

That will output the new file to the console and you can redirect it wherever you need. Or you can use -i to edit inplace.

EDIT: Forgot to escape the slash

Stephan
I'd choose a different delimiter, maybe 's!...!...!g', to avoid having to escape. But that's personal opinion.
ephemient
@ephemient: That's probably a better choice, but I feel odd using anything but slash
Stephan
+3  A: 

You can also use:

sed -e 's!<html>!<html><link rel="stylesheet" type="text/css" href="LivingInStyle.css">!' < file

i.e. use another separator instead of escaping the slash.

Arnaud