Reputation: 457
not quite sure how to get this working. apologies, i'm kinda new to this.
so i have a file with a line that starts with
<script type="text/javascript">var NREUMQ=NREUMQ
I want to repace that line with
</head>
I can't seem to get it going. I understand I need something like this:
sed 's/^ <script type="text/javascript">var NREUMQ=NREUMQ/hello/g index3.html
but I am not sure where to escape the special characters. obviously the '/' needs it. can anyone lend a hand?
Upvotes: 1
Views: 1918
Reputation: 10039
sed "/<script type=\"text\/javascript\">var NREUMQ=NREUMQ/ s#.*#</head>#"
You can also keep the space at the begining with s#^\( *\).*#\1</head>#"
Upvotes: 0
Reputation: 55
You can use:
sed 's|<script type="text/javascript">var NREUMQ=NREUMQ|</head>|'
Upvotes: 0
Reputation: 58324
You can escape just about anything using backslash:
sed "s/^ <script type=\"text\/javascript\">var NREUMQ=NREUMQ/hello/g" index3.html
The nice thing about sed
is that you can also use alternate delimeters. It will use whatever you put after the s
, which means you wouldn't have to escape a slash:
sed "s#^ <script type=\"text/javascript\">var NREUMQ=NREUMQ#hello#g" index3.html
Upvotes: 2
Reputation: 6994
you can escape them by backslash; but you can also write
sed 's!...!...!'
(the '!' can be an arbitrary character)
Upvotes: 1
Reputation: 786359
Use alternate regex delimiter, other than /
since your matching text has /
in it:
sed -i.bak 's~^ *<script type="text/javascript">var NREUMQ=NREUMQ~</head>~' index3.html
Upvotes: 2