0

Is it possible to grep a value then store it in a file via batch file??

Like for example,

grep "error 404" Mow*2015.txt | wc -l
grep "error 403" Mog*2015.txt | wc -l

Then I want it to put in a batch for it to generate another txt file or other extension.

set ARH = * grep for the 404 *
set ARG = * grep for the 403 *

ECHO %ARG% %ARH% >> admin.log

Is it possible to do so?

Jeeva Suriyaa
  • 96
  • 1
  • 12
  • 1
    Possible duplicate of [Windows batch assign output of a program to a variable](http://stackoverflow.com/questions/2323292/windows-batch-assign-output-of-a-program-to-a-variable) – wOxxOm Oct 26 '15 at 10:19

1 Answers1

1

I suppose you have installed cygwin or Windows Services for UNIX.But you can use windows command only to achieve what you want:

for /f "delims=" %%# in (
  '"%windir\system32\FIND.EXE%" "error 404" mow*2015.txt' ^| "%windir\system32\FIND.EXE%" /c /v /n ""
) do set "ARH=%%#"

for /f "delims=" %%# in (
  '"%windir\system32\FIND.EXE%" "error 403" mow*2015.txt' ^| "%windir\system32\FIND.EXE%" /c /v /n ""
) do set "ARG=%%#"

ECHO %ARG% %ARH% >> admin.log
npocmaka
  • 55,367
  • 18
  • 148
  • 187