[SOLVED] grep + HTML angle brackets?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Shohreh
Posts: 33
Joined: 26 Feb 2020 08:05

[SOLVED] grep + HTML angle brackets?

#1 Post by Shohreh » 13 Sep 2023 06:29

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.
Last edited by Shohreh on 14 Sep 2023 08:00, edited 1 time in total.

mataha
Posts: 35
Joined: 27 Apr 2023 12:34

Re: grep + HTML angle brackets?

#2 Post by mataha » 13 Sep 2023 06:54

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>

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: grep + HTML angle brackets?

#3 Post by dbenham » 13 Sep 2023 07:40

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.

Shohreh
Posts: 33
Joined: 26 Feb 2020 08:05

Re: grep + HTML angle brackets?

#4 Post by Shohreh » 14 Sep 2023 08:00

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.

Post Reply