Print section in text file on windows

This will use awk tool.

for example input.txt:
<html>
<body>
<pre class="hello">
<p>Paragrapg</p>
<p>Another paragraph two</p>
</pre>
</body>
</html>
Run this command:
awk "/pre class/,/two/" input.txt
Output will be:
<pre class="hello">
<p>Paragrapg</p>
<p>Another paragraph two</p>
To save output in another file use:
awk "/pre class/,/two/" input.txt > output
If you want to capture full html tag you have to know that / in awk should be writed as \/ and " should be writed as a triple """:
awk "/<pre class="""hello""">/,/<\/pre>/"
and now we capture full html tag:
<html>
<body>
<pre class="hello">
<p>Paragrapg</p>
<p>Another paragraph two</p>
</pre>
</body>
</html>
Here is awk utility:

No comments: