It's easy to hightlight text with sed!
So make a bat file out of it!
Then you can pipe stuff to highlight. So easy to remember! It's great if you get more grep results than you expect, but you still don't want to JUST return the 1 line you're looking for:
It's great for highlighting the secondary thing you're looking for in something. Here's my sed version:
Storytime below:
I used to do this in a much more complicated way that involved changing the environment variables that control how grep responds, as well as changing the escape character because I spent years not realizing enclosing it in quotes would keep it from escaping. So the actual working BAT file on my hardrive is total madness:
And if you want a simple validate-in-path.bat:
Code:
echo duck duck goose duck duck | sed '/goose/,${s//\x1b[1;33;41m&\x1b[0m/g;b};$q5'
So make a bat file out of it!
Code:
@echo off
sed '/%@UNQUOTE[%*]/,${s//\x1b[1;33;41m&\x1b[0m/g;b};$q5'
Then you can pipe stuff to highlight. So easy to remember! It's great if you get more grep results than you expect, but you still don't want to JUST return the 1 line you're looking for:
It's great for highlighting the secondary thing you're looking for in something. Here's my sed version:
Storytime below:
I used to do this in a much more complicated way that involved changing the environment variables that control how grep responds, as well as changing the escape character because I spent years not realizing enclosing it in quotes would keep it from escaping. So the actual working BAT file on my hardrive is total madness:
Code:
@echo off
:PUBLISH:
:DESCRIPTION: A way to highlight text. Basically a grep-like functionality. Great for doing secondary greps on already grepped blocks of text that you *do* want to see. can be done with grep, but we prefer using sed.
REM call debug "parameters are %*"
set SEARCHFOR1=%*
set SEARCHFOR2=%@UNQUOTE[%*]
:call debug "Searchfor1/2 are '%SEARCHFOR1%' and '%SEARCHFOR1%'"
::::: DEBUGS:
set DEBUG_HIGHLIGHT=0
::::: DOCUMENTATION ONLY: SUGGESTED EXAMPLE ENVIRONMENT VALUES:
:set GREP_COLORS_NORMAL=fn=1;33:ln=1;36;44
:set GREP_COLOR_NORMAL=1;33;42
:set GREP_COLORS_HILITE=fn=1;34:ln=1;37;44
:set GREP_COLOR_HILITE=1;41;37
::::: ENVIRONMENT VALIDATION:
if "%ENVIRONMENT_VALIDATION_HIGHLIGHT_ALREADY%" eq "1" goto :AlreadyValidated
call validate-environment-variables GREP_COLOR_NORMAL GREP_COLORS_NORMAL GREP_COLOR_HILITE GREP_COLORS_HILITE
call validate-in-path sed
set ENVIRONMENT_VALIDATION_HIGHLIGHT_ALREADY=1
:AlreadyValidated
::::: STORE ORIGINAL GREP-COLOR AND ESCAPE KEY, SWAP OUT FOR HILIGHT-SPECIFIC GREP-COLOR:
set GREP_COLORS=%GREP_COLORS_HILITE%
::::: DEBUG INFO:
if %DEBUG_HIGHLIGHT ne 1 goto :No_Debug
echo SEARCHFOR1=%SEARCHFOR1%
echo SEARCHFOR2=%SEARCHFOR2%
echo sed '/%SEARCHFOR1/,${s//\x1b[1;33;41m&\x1b[0m/g;b};$q5' [with searchfor1]
echo sed '/%SEARCHFOR2/,${s//\x1b[1;33;41m&\x1b[0m/g;b};$q5' [with searchfor2]
:No_Debug
::::: DO THE ACTUAL HIGHLIGHTING:
call change-escape-character-to-tilde silent
sed '/%SEARCHFOR2/,${s//\x1b[1;33;41m&\x1b[0m/g;b};$q5'
call change-escape-character-back silent
::::: RESTORE ORIGINAL GREP-COLORS AND ESCAPE CHARACTER:
set GREP_COLOR=%GREP_COLOR_NORMAL%
set GREP_COLORS=%GREP_COLORS_NORMAL%
And if you want a simple validate-in-path.bat:
Code:
@echo off
for %arg in (%*) do (
set search=%@SEARCH[%arg]
REM echo * search = %search%
if "%search%" eq "" (
echo FATAL ERROR! %arg is not in your path, and needs to be.
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
pause
)
)