How do I escape > in grep in a for loop???

Microsoft Windows
Post Reply
Rekrul
Posts: 52
Joined: 2021-Aug-15, 11:29 pm

How do I escape > in grep in a for loop???

Post by Rekrul »

I need to use grep to find the number of lines containing the sequence of characters;

">

This works when entered directly into the command line and gives me the count of matching lines;

Code: Select all

grep -c "\">" "filename.txt"
This does not;

Code: Select all

for /f %E in ('grep -c "\">" "filename.txt"') do echo %E
Nor does this;

Code: Select all

for /f %E in ('grep -c  "\"^>" "filename.txt"') do echo %E
How can I escape the greater than in the for loop so that the count gets placed into the token?
Rekrul
Posts: 52
Joined: 2021-Aug-15, 11:29 pm

Re: How do I escape > in grep in a for loop???

Post by Rekrul »

Well, after MUCH experimentation, I discovered that this works in a script;

Code: Select all

@echo off
set Tag=\"^>
setlocal enabledelayedexpansion
for /f %%E in ('grep -c "!Tag!" "%Filename%"') do endlocal & set Count=%%E
echo %Count%
[/quote]
Post Reply