Reputation: 81
$ sed -n '/<body>/,/<\/body>/p' hello.html
The command works fine and gives desired result.
I want to print only those which lines between and (including these tags as well) of an html
file named as hello.html
But when I try to create a sed
script named as html-body.sed
with this command as:
-n /<body>/,/<\/body>/p
when I try to run it....
$ sed -f html-body.sed hello.html
It gives error as:
sed: file html-body.sed line 1: unknown command: `-'
Why this same command, when written in sed
script gives this error.
Upvotes: 0
Views: 326
Reputation: 881993
The sed
script is only allowed to hold sed
text processing commands, not options to sed
itself.
Those options are required to be on the actual command invocation.
You can still use a sed
script but you have to call it with the options:
sed -n html-body.sed hello.html
One thing you can do is switch to a more powerful text processing tool such as awk
with the following script:
/<body>/ {e=1}
{if(e==1){print}}
/<\/body>/ {e=0}
Then simply run:
awk -f thatscript.awk inputfile
Upvotes: 1