How can I colorize grep results using a Windows bat file? -


i created bat file using windows port of grep allows me search strings context search. looks this:

grep -c -i "%1" %2  

if invoke this: grep -c -i "smith" mydoc.doc exact results looking for:

bruce korn 10 smith street  durham, nc  

but know of way add windows color command bat "smith" displayed in green (something "color 0f" ) added pipe or that? can not figure out how (or if it's possible)

(the grep port not have coloring or highlighting capability)

i found batch file while ago. unfortunately can't find source, or remember wrote it. see , able provide link.

@echo off setlocal enabledelayedexpansion /f "tokens=1,2 delims=#" %%a in ('"prompt #$h#$e# & echo on & %%b in (1) rem"') (   set "del=%%a" ) echo next line in color: call :colortext 0c "there ashstorm!" echo red. call :colortext 0a "you survived it."  goto :eof  :colortext echo off echo %del% > "%~2" findstr /v /a:%1 /r "^$" "%~2" nul del "%~2" > nul 2>&1 goto :eof 

you should able adapt using loop change colour of first line.

replace section;

echo next line in color: call :colortext 0c "there ashstorm!" echo red. call :colortext 0a "you survived it." 

with following:

set c=1 /f "delims=" %%a in ('grep -c -i "%1" %2') (     if !c!==1 (call :colortext 02 "%%a") else echo %%a     set /a c+=1 ) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -