-1

so i have a problem with set a variable with FINDSTR value in it. I have to set the variable so i can output the value to text file that i wanted

i already tried to set the variable in for looping every findstr value that i get, but the output didnt like i wish too

set /p tanggal="Masukan Bulan/Tahun: "

echo.
set /p namaService="Masukan services path: "

setlocal enabledelayedexpansion

echo Services,tanggal,hit >> Summary_%tanggal:/=-%_%namaService:/=-%.txt

FOR /L %%A IN (1,1,31) DO (
     if %%A LEQ 9 (
        set "jumlahHit = FINDSTR /R /N "0%%A/%tanggal%.*%namaService%" access* | FIND /C ":""
        echo !jumlahHit! >> Summary_%tanggal:/=-%_%namaService:/=-%.txt
     ) else (
        set "jumlahHit = FINDSTR /R /N "%%A/%tanggal%.*%namaService%" access* | FIND /C ":""
        echo !jumlahHit! >> Summary_%tanggal:/=-%_%namaService:/=-%.txt
     )
)
echo Total : >> Summary_%tanggal:/=-%_%namaService:/=-%.txt
FINDSTR /R /N "%tanggal%.*%namaService%" access* | FIND /C ":" >> Summary_%tanggal:/=-%_%namaService:/=-%.txt

I expect the output to be some value with findstr result but the output in the file say echo is off

Services,tanggal,hit 
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
Total : 
152720

is that any other way to set the findstr result in looping?

1 Answers1

-1

You have two problems:

Variable Names

Variable names are exactly as you type them:

set variable = string

This sets variable{space} to the value {space}string. So to print that variable, you'd need to have

echo %variable %

This is why your lines are full of ECHO is off.


You can't set variable values from inline commands

An example of what I mean:

set variable=dir
echo %variable%
:: output is "dir"

See this question on how to set value of a variable to the output of a command.

BDM
  • 3,760
  • 3
  • 19
  • 27