Page 1 of 1

[SOLVED] grep + HTML angle brackets?

Posted: 13 Sep 2023 06:29
by Shohreh
Hello,

Unless there's a better alternative, I tried GNU grep 2.5.4 but it fails finding lines with HTML tags.

Is there a way in Windows10's cmd to accept angle brackets?

Code: Select all

C:\>grep --version

C:\>grep --help

C:\>grep

C:\>grep -Poha "<h2>" input.html

C:\>grep -Poha "^<h2^>" input.html
Thank you.

Re: grep + HTML angle brackets?

Posted: 13 Sep 2023 06:54
by mataha
May I recommend ripgrep instead?

Code: Select all

> rg --pcre2 --text --only-matching --no-filename "<html>" index.html
1:<html>

> rg -PoIa "<html>" index.html
1:<html>
Although cmd should have no problems accepting angle brackets as long as they're within quotes.
The following is equivalent:

Code: Select all

> rg --pcre2 --text --only-matching --no-filename ^<html^> index.html
1:<html>

Re: grep + HTML angle brackets?

Posted: 13 Sep 2023 07:40
by dbenham
The following works fine for me on GNU grep 2.5.1

Code: Select all

C:\>grep -Poha "<h2>" input.html
Windows command line treats quoted angle brackets as literals. I don't think this is a command line issue, unless possibly your actual command is more complicated than what you are showing, causing the search string to not be quoted as you think.

So either this is simply a grep issue, in which case this is not the correct forum.

Or if this really is a command line issue then you need to show a specific case that is failing, with test file, failing command line, and result.

Re: grep + HTML angle brackets?

Posted: 14 Sep 2023 08:00
by Shohreh
Thanks for the infos.

Turns out the "Binaries" file also requires the "Dependencies", which I missed.

https://gnuwin32.sourceforge.net/packages/grep.htm

It's working OK.