How do I write a ">" into a txt file with batch? - html

I need to write an html document from a batch file and this document contains the ">" character. When I try to write a ">" character to a file though, it cuts off and doesn't write.
Example -
Echo <HTML> > HtmlDoc.html
The output here to the file would be
<HTML
How do I fix this?

You need to escape the special characters:
echo ^<html^> > HtmlDoc.html
For more information about escapes in batch scripting, read http://www.robvanderwoude.com/escapechars.php

Related

Do you have any function or tools to convert simple html to special code which I like?

I want to convert a simple code to an special code which I like. see this simple code :
<html>
<body>
The content of the document
</body>
</html>
convert to :
<html>\n\t<body>\n\t\t The content of the document \n\t</body>\n</html>
(convert linebreak to \n ; convert tabs to \t ; convert " to \")
And finally put them in one line. just one line.
Can you suggest me a good function or tools for this work?
First to come into mind is Notepad++ for me.
In Macro menu
You can start recording your actions
Replace all linebreaks with \n
Replace all tabs with \t
Replace all " with \"
And save your macro to use whenever you want to use again

How to output "<" and ">" symbols to a text file using batch script

I created a simple batch script to format some HTML codes that i use on a regular basis. My current workaround is outputting 888 and 999 and going back into the text file and replacing all 888's with a < and all 999's with a >. I know batch uses these symbols and redirects so i wanted to know if there was a way to bypass this. Below is an example.
888div id="bestlinkstop"999
888a href=" " target="_blank"999 888img src=" "999 888/a999
888/div999
changing all 8's and 9's to < and >
<div id="bestlinkstop">
<img src=" ">
</div>
Thanks in advance
You can use the Windows escape character is ^ to escape the brackets.
Something like
echo mystring ^< div id="bestlinkstop" ^> something >>myfile.txt

Single quotes (') is replaced by &apos;

I am using a third party jar file to generate svg file. I am expecting something like myfunction('divId'); But output is coming as myfunction(&apos;divId&apos;); Is there any way to avoid &apos;.
Assuming you're using Java (jar file), you could call String#replace() like so -
String str = "myfunction(&apos;divId&apos;);";
str = str.replace("&apos;", "'");
System.out.println(str);
Outputs
myfunction('divId');
Perhaps you can try defining a character set (i.e., <meta charset="UTF-8">) in your document header.
&apos and &amp are not in the list of HTML4 entities, use &#39 instead.
myfunction(&#39divid&#39)
should work.

How to write the "greater than symbol" in a HTML file using a batch file

I was wondering if it is possible to use the "<" and ">" when writing to a HTML file from a batch file. I need this so I can write certain things to html files.
I tried the following and it didn't work:
ECHO </html> >>File.html
PS. Thanks in advance
It's a little messy, but you have to escape the < and > characters using ^:
echo ^<html^> >> a.html
echo ^<body^>Hi^</body^> >> a.html
echo ^</html^> >> a.html
Result:
<html>
<body>Hi</body>
</html>
You can escape the character by placing a carot sign (^) in front of "<" and ">".
echo ^</html^> >>File.html

Regex conditional

How would I write a RegEx to:
Find a match where the first instance of a > character is before the first instance of a < character.
(I am looking for bad HTML where the closing > initially in a line has no opening <.)
It's a pretty bad idea to try to parse html with regex, or even try to detect broken html with a regex.
What happens when there is a linebreak so that the > character is the first character on the line for example (valid html).
You might get some mileage from reading the answers to this question also: RegEx match open tags except XHTML self-contained tags
Would this work?
string =~ /^[^<]*>/
This should start at the beginning of the line, look for all characters that aren't an open '<' and then match if it finds a close '>' tag.
^[^<>]*>
if you need the corresponding < as well,
^[^<>]*>[^<]*<
If there is a possibility of tags before the first >,
^[^<>]*(?:<[^<>]+>[^<>]*)*>
Note that it can give false positives, e.g.
<!-- > -->
is a valid HTML, but the RegEx will complain.