Most time Just 1 command line to solve your daily text or file processing work, pipe endless.
Since 2019-07-19 a Visual Studio Code extension: vscode-msr (source code: here) to help your coding work.
Match/Search/Replace: on Windows/MinGW/Cygwin + Ubuntu/CentOS/Fedora + Darwin + FreeBSD
- Match/Search/Replace* Lines/Blocks in Files/Pipe.
- Filter/Load/Extract/Transform/Stats/* Lines/Blocks in Files/Pipe.
- Execute transformed/replaced result lines as command lines.
Not-IN-latter: on Windows/MinGW/Cygwin + Ubuntu/CentOS/Fedora + Darwin + FreeBSD
- Get
UniqueorRawExclusive/Mutual Line-Set or Key-Set; - Stats + Get top distribution in Files/Pipe.
- Remove(Skip) Line-Set or Key-Set matched in latter file/pipe.
| Windows | MacOS | Linux |
|---|---|---|
| Summary table | Summary table | Summary table |
| 2X~15X+ > findstr | 3X~10X+ > grep | 1.5~3X+ vs 1.5~3X+ |
- To quickly get msr/nin without slowly cloning + storing many files:
- Method-1: Install a tiny extension vscode-msr to auto check + download by system + terminal.
- Method-2: Manually click the URLs in msr download commands or nin download commands.
- To clone all files:
- git clone https://github.com/qualiu/msr (run
git reset --hard origin/masterwhen pulling conflicts).
- git clone https://github.com/qualiu/msr (run
- Preview functions: See HTML screenshots like msr or nin or vivid colorful demo on Windows.
- Helpful repos: msrTools(like psall.bat + pskill.bat + Run-SQL.ps1) + msrUI + msr-nin repo(if you're in Microsoft).
- Just general
Regexas C++, C#, Java, Scala, needless to learn strange Regex syntax likeFINDSTR,Awk,Sedetc. - Search: (
-i=--ignore-caselike:-i -tor-itor-ix)- Normal search: msr -r -p
"path1,pathN"-i -t"Regex-pattern"-x"and-plain-text"Optional-Args - Advanced search: code mining with the cooked
doskeys/aliasinCMD/Bashconsole or VSCode terminals.
- Normal search: msr -r -p
- Replace: (You can use both
-xand-t)- Preview changes: msr -r -p
path1,pathN-t"Regex-pattern"-o"replace-to"-j Optional-Args - Replace files: msr -r -p
path1,pathN-t"Regex-pattern"-o"replace-to"-R Optional-Args
- Preview changes: msr -r -p
- Use optional args like -P -A -C or -PAC or -PIC to get pure result as same as other tools like
grep/findstr. - All options are optional + no order + effective meanwhile; Free with abbreviations or full-names(like -i =
--ignore-case).
- Just run
msr --helpormsr -hormsr(same fornin) to see usage and examples, brief quick start at the bottom of output. - For msr:
- See Scenario Glance + Brief Summary of msr EXE at the bottom of running
"msr -h". - See additional UI helper: msrUI to auto show usage + example + command line.
- See Scenario Glance + Brief Summary of msr EXE at the bottom of running
- For msr + nin: Also can see tools/readme.txt
- Zoom out following screenshots to 90% or smaller if it's not tidy or comfortable.
You can use a tool folder (already in %PATH% or $PATH) instead of using %SystemRoot% or /usr/bin/ (you can also link msr to there).
Validation with md5.txt use md5sum xxx like: md5sum msr* | msr -t "\s+\**" -o " " -PAC | nin md5.txt -m
- msr-Color-Doc on Windows + MinGW: (You can get
wgetby choco or cygwin; or get msr by PowerShell)- x86_64 + Arm64:
- wget https://github.com/qualiu/msr/raw/master/tools/msr.exe -O
msr.exe.tmp&&move /y msr.exe.tmp msr.exe&&icacls msr.exe /grant %USERNAME%:RX&&move msr.exe %SystemRoot%\
- wget https://github.com/qualiu/msr/raw/master/tools/msr.exe -O
- Windows
32-bit:- wget https://github.com/qualiu/msr/raw/master/tools/msr-Win32.exe -O
msr.exe.tmp&&move /y msr.exe.tmp msr.exe&&icacls msr.exe /grant %USERNAME%:RX&&move msr.exe %SystemRoot%\
- wget https://github.com/qualiu/msr/raw/master/tools/msr-Win32.exe -O
- msr-Color-Doc on Cygwin x86_64 (one command + green install-cygwin.bat):
- wget https://github.com/qualiu/msr/raw/master/tools/msr.cygwin -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&mv msr /usr/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr.cygwin -O
- x86_64 + Arm64:
- msr-Color-Doc on MacBook
Arm64(Darwin):- wget https://github.com/qualiu/msr/raw/master/tools/msr-arm64.darwin -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&sudo mv msr /usr/local/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr-arm64.darwin -O
- msr-Color-Doc on Linux + Fedora + WSL + Ubuntu:
- x86_64 Linux (CentOS / Ubuntu / Fedora):
- wget https://github.com/qualiu/msr/raw/master/tools/msr.gcc48 -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&sudo mv msr /usr/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr.gcc48 -O
- x86
32-bitlike 32-bit CentOS:- wget https://github.com/qualiu/msr/raw/master/tools/msr-i386.gcc48 -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&sudo mv msr /usr/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr-i386.gcc48 -O
- Arm64:
- wget https://github.com/qualiu/msr/raw/master/tools/msr-aarch64.linux -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&sudo mv msr /usr/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr-aarch64.linux -O
- x86_64 Linux (CentOS / Ubuntu / Fedora):
- FreeBSD
- amd64:
- wget https://github.com/qualiu/msr/raw/master/tools/msr-amd64.freebsd -O
msr.tmp&&mv -f msr.tmp msr&&chmod +x msr&&sudo mv msr /usr/bin/msr
- wget https://github.com/qualiu/msr/raw/master/tools/msr-amd64.freebsd -O
- amd64:
Validation with md5.txt use md5sum xxx like: md5sum nin* | msr -t "\s+\**" -o " " -PAC | nin md5.txt -m
- nin-Color-Doc on Windows + MinGW: (You can get
wgetby choco or cygwin; or get nin by PowerShell)- x86_64 + Arm64:
- wget https://github.com/qualiu/msr/raw/master/tools/nin.exe -O
nin.exe.tmp&&move /y nin.exe.tmp nin.exe&&icacls nin.exe /grant %USERNAME%:RX&&move nin.exe %SystemRoot%\
- wget https://github.com/qualiu/msr/raw/master/tools/nin.exe -O
- Windows
32-bit:- wget https://github.com/qualiu/msr/raw/master/tools/nin-Win32.exe -O
nin.exe.tmp&&move /y nin.exe.tmp nin.exe&&icacls nin.exe /grant %USERNAME%:RX&&move nin.exe %SystemRoot%\
- wget https://github.com/qualiu/msr/raw/master/tools/nin-Win32.exe -O
- nin-Color-Doc on Cygwin x86_64 (one command + green install-cygwin.bat):
- wget https://github.com/qualiu/msr/raw/master/tools/nin.cygwin -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&mv nin /usr/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin.cygwin -O
- x86_64 + Arm64:
- nin-Color-Doc on MacBook
Arm64(Darwin):- wget https://github.com/qualiu/msr/raw/master/tools/nin-arm64.darwin -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&sudo mv nin /usr/local/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin-arm64.darwin -O
- nin-Color-Doc on Linux + Fedora + WSL + Ubuntu:
- x86_64 Linux (CentOS / Ubuntu / Fedora):
- wget https://github.com/qualiu/msr/raw/master/tools/nin.gcc48 -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&sudo mv nin /usr/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin.gcc48 -O
- x86
32-bitlike 32-bit CentOS:- wget https://github.com/qualiu/msr/raw/master/tools/nin-i386.gcc48 -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&sudo mv nin /usr/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin-i386.gcc48 -O
- Arm64:
- wget https://github.com/qualiu/msr/raw/master/tools/nin-aarch64.linux -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&sudo mv nin /usr/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin-aarch64.linux -O
- x86_64 Linux (CentOS / Ubuntu / Fedora):
- FreeBSD:
- amd64:
- wget https://github.com/qualiu/msr/raw/master/tools/nin-amd64.freebsd -O
nin.tmp&&mv -f nin.tmp nin&&chmod +x nin&&sudo mv nin /usr/bin/nin
- wget https://github.com/qualiu/msr/raw/master/tools/nin-amd64.freebsd -O
- amd64:
Zoom out following screenshots to 90% or smaller if it's not tidy or comfortable.
- Windows vivid demo test (run
git clean -dfxbefore re-running test if test failed). - Linux demo and test.
- Single exe for multiple platforms: Windows + Cygwin + WSL + Ubuntu/CentOS/Fedora/Darwin
- Smart Loading files with 8 composable kinds of filters:
- 5 pairs of file attribute filters:
- File name patterns (-f/--nf)
- Directory patterns (-d/--nd)
- Full path patterns:
- Regex:
- --pp
need-regex - --np
exclude-regex
- --pp
- Texts:
- --xp
"test,mock,/obj/" - --sp
"src/,/common/"
- --xp
- Regex:
- File size range:
- --s1
1B; --s21.6MB - --s1
file1-as-size; --s2file2
- --s1
- File modification time range:
- --w1
2015-07-01T18:30:00; --w22015-08or"2015-07-01 20:00" - --w1
10days; --w2+10d - --w1
file1_as_time_plus_1s_if_no_w2 - --w1
file1_as_time; --w2file_or_time_or_offset
- --w1
- 3 kinds of file row / block filters to start/stop/skip reading/replacing each files/pipe:
- Row/line number begin/end (-L, -N) like:
-L 30 -N 60same with-L 30 -N +30-L 30 -N 0same withL 30 -N 30
- Block begin/end patterns (-b, -Q) for each block in each file/pipe; with -q to stop at once for pipe/each file.
- Normal begin/end patterns (b, -q).
- Row/line number begin/end (-L, -N) like:
- 5 pairs of file attribute filters:
- Process pipe (output of self/other commands) endless as you want.
- Two composable single exe: msr.exe/cygwin/gcc* especially powerful with nin.exe/cygwin/gcc*.
- 70 composable options for msr and 30 composable options for nin (just run them without parameters to get colorful usage/examples or see readme.txt) for further extractions/mining.
msr --help # same as running: "msr -h" or "msr"
nin --help # same as running: "nin -h" or "nin"
msr | msr -t "^\s*-{1,2}\S+" -q "^\s*-h\s+" --nt "--help"
nin | msr -t "^\s*-{1,2}\S+" -q "^\s*-h\s+" --nt "--help"- Cannot process Unicode files/pipe so far; Fine with UTF-8 and ANSI etc.
Besides the doc here and test scripts, some script/batch/shell files are also examples in this and sub-folders.
Use the rich searching options of like below, combine these optional options (You Can Use All):
- Set searching paths: (Can use both)
- Recursively(
-r) search one or more files or directories, like: -r -pfile1,folder2,file2,folder3,folderN - Read paths (path list) from files, like: -w
path-list-1.txt,path-list-2.txt
- Recursively(
- Set max search depth (begin from input folder), like:
-k
16(default max search depth =33). - Filter text by
line-matching(default) orwhole-file-text-matching(add -S / --single-line Regex mode):- Ignore case for text matching:
- Add -i (
--ignore-case)
- Add -i (
- Regex patterns:
- -t
should-match-Regex-pattern - --nt
should-not-match-Regex-pattern
- -t
- Plain text:
- -x
should-contain-plain-text - --nx
should-not-contain-plain-text
- -x
- Ignore case for text matching:
- Single-line-Regex mode (-S) for Regex
"^"and"$":- Treat each file as one single line. If reading pipe, treat whole output as one line.
- If block matching (used
-b+-Q): Treat each block as one line in a file. Useful like removing a whole block.
- Filter
file name: -fshould-match-Regex, --nfshould-not-match-Regex - Filter
directory name: -dat-least-one-match-Regex, --ndnone-should-match-Regex - Filter
full path pattern: --ppshould-match-Regex, --npshould-not-match-Regex - Filter
full or sub paths: --xp"d:\win\dir,my\sub,\bin\,\out\\", --sp"\src\,common"- Newer msr support universal slash
/for--pp/--np+--sp/--xplike:- --xp
"d:/win/dir,my/sub,/bin/,/out/" - Check if support universal slash by command:
msr --help | msr -x "Support '/' on Windows"
- --xp
- Newer msr support universal slash
- Skip/Exclude link files: --xf
- Skip/Exclude link folders: --xd
- Try to read once for link files: -G (link files' folders must be or under input root paths of -p or/and -w)
- Filter
file size: --s1 <= size <= s2 , like set one or two: --s11B--s21.5MB - Filter
file time: like --w12015-07, --w2"2015-07-16 13:20"or2015-07-16T13:20:01(quote it if has spaces). - Filter rows by begin + end row numbers: like -L 10 -N 200 (for each file).
- Filter rows by begin + end Regex: like -b
"^\s*public.*?class"-q"^\s*\}\s*$" - Filter rows by 1 or more blocks: -b
"^\s*public.*?class"-Q"^\s*\}\s*$" - Filter rows by 1 or more blocks + stop like: -b
"^\s*public.*?class"-Q"^\s*\}\s*$"-q"stop-matching-regex" - Quickly pick up
head{N}results + Jump out(-J), like: -H30-J or -J -H300or -JH300etc. - Don't color matched text: -C (
Fasterto output, and must be set forLinux/Cygwinto further process). - Output summary
infoto stderr + hidewarnings in stderr(like BOM encoding): -I : Like -I -C or -IC or -J -I -C or -JIC etc. - Use --force to force replace BOM files which header != 0xEFBBBF (if UTF8 encoding is acceptable).
- Use
--keep-coloron Windows/MinGW if you want to keep color for pipe or output file. - Use
--colorsto change/set colors for match-result / file-paths / final summary: See Set-Or-Change-Color-Groups. - Use
--unix-slash 1to output forward slash (/) of file paths on Windows (msr/ninaccepts 2 types of slash:'/'and'\'). - Use
--exit number/Math/Regexto change exit code, like:- Use
--exit gt255-to-255for Cygwin/Linux/MacOS shell. - Use
--exit gt127-to-127for MinGW on Windows. - It's not recommended to set global MSR_XXX environments in your machine, because this may cause errors for other people/machines.
- You can set environment temporarily(like vscode-msr) in a command line or in a script header like:
export MSR_EXIT=gt0-to-0,le0-to-1(this will change totraditional return value style).- This is safe (only impact 1 script) + Convenient yourself if you're used to traditional usage.
- You can set environment temporarily(like vscode-msr) in a command line or in a script header like:
- Use
-
Search code or log:
- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-x"And-Plain-text"--nt ... --nx ... --nd ... -d ... --pp ... --np ... --xp ...
- msr -rp
-
Search files + Extract + Transform to target text/value:
- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-o"Replace-To"+ Optional Args
- msr -rp
-
Get matched file list (You can omit -o xxx). You can also append
| msr -t "(.+)" -o "command \1" -Xto process files.- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-o"Replace-To"-l + Optional Args
- msr -rp
-
Replace text:
- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-o"Replace-To"+ Optional Args
- msr -rp
-
Just preview changed files + lines:
- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-o"Replace-To"-j + Optional Args
- msr -rp
-
Replace files (
-R) and backup (Add-K):- msr -rp
folder1,folder2,file1,fileN-t"Regex-Pattern"-o"Replace-To"-R + Optional Args
- msr -rp
-
Insert or add a line with same indention:
- msr -rp
paths-f"\.(xml|json)$"-it"^(\s*)(regex-groups)"-o"\1\2\n\1{add-your-line}"-R
- msr -rp
-
Replace or remove specific matched block (multiple lines) like code files and config files(
XML/JSON/YAML/INIetc.):- msr -rp
paths-f"\.xml$"-b"^\s*</Tag1>"-Q"^\s*</Tag1>"-it"match-regex"-o"replace-to or empty/to-remove"-R with -S if you need.
- msr -rp
-
Sort log files by time text (auto set to previous line's time if a line no time) + Get error top distribution:
- msr -rp
paths-F"\d{4}-\d{2}-\d{2}\D\d+:\d+:\d+[\.,]?\d*"| nin nul"\.(\w+Exception)\b"-p -d -O -w
- msr -rp
-
Grep numbers in files or pipe, and sort (-s) as number (-n) + Show stats:
Count+Sum+Max+Min+Median+Average+Standard-Deviation+Percentilesetc. :- msr -rp
paths-f"\.log$"-t"time cost = (\d+\.?\d*)"-n -s"" - xxx-cmd-output | msr -t
"(match-1), value = (-?\d+\.?\d*)-n -s"value = (-?\d+\.?\d*)"
- msr -rp
-
Further processing based on summary (generate text, or command lines with
-Xto execute):- msr -rp
paths-itregex-xtext--ntskip-regex--nxskip-text-H 0 -c key message | msr -t"^Matched (\d+) .*? -c (key message)"-o"replace to text or command line"-X
- msr -rp
It's better to use "\1" than "$1" which let you easier to copy/migrate your replacing command lines.
- For example: msr -p paths -i -t
".*?text = (capture1).*?(capture2).*"-o "\1 \2""\1"="$1"for CMD console or batch files (*.bator*.cmd) on Windows."\1"='$1'for PowerShell (Windows / Linux) or Bash (Linux / Cygwin).
- Execute output lines as command lines:
- Often use -X -M (or -XM) to hide final summary of executions.
- Use -X -I to avoid show each command's return value + time cost + command line.
- Use -X -P -I or -X -A to hide all.
- Run a command, exit if return != 0:
echo command line | msr -XM || exit -1(useexit /b -1on Windows CMD) - Directly run a simple command line:
msr -XM -z "command line" || exit -1(useexit /b -1on Windows CMD). - Set UTF-8 no-BOM encoding if matching head failed due to encoding changed by
Python/PowerShell/etc, like:[Console]::InputEncoding = New-Object System.Text.UTF8Encoding $falsefile/pipe/command output | msr -t "^head-search-Regex" -o "replace-to" ...
- You don't need to change encoding if execute(-X) output, msr will auto detect and trim the BOM header before executing:
file/pipe/command output | msr -Xfile/pipe/command output | msr -t "search-Regex" -o "replace-to" ... -X
- Replace Files(-R):
- Use -j to preview changes before replacing(
-R). - Use -M -T 0 to hide summary + final changed file list, only output immediate change info (hide by
-H 0).
- Use -j to preview changes before replacing(
:: No order but case-sensitive. Free to use abbreviations(-i = --ignore-case; -r = recursive; -k = --max-depth)
msr
-r
-p path1,path2,pathN
-w path-list-file-1,path-list-file-N
-k 18
-i
-t "Regex-to-Search/Match"
-x `"And-Plain-text"`
-e `"Extra-Regex-to-Add-Color"`
-o `"Replace-{matched result of -x or -t}-To-this"`
--nt "Exclude-Regex"
--nx "Exclude-Plain-Text"
-S : Use single-line-Regex-mode for whole text in pipe or each-file or each-block
-f "File-Name-Regex"
--nf "Exclude-File-Name-Regex"
-d "Match-Folder-Name-Regex"
--nd "^(\.git|bin|Debug|Release|static|packages|test)$"
--np "Exclude-Full-Path-Regex"
--pp "Match-Full-Path-Regex"
--xp "Exclude-Full-or-SubPath1,FullPath2,SubPathN"
--sp "Need-SubPath1,SubPath2"
--s1 1B
--s2 10.50MB
--w1 "2015-12-30 10:20"
--w2 "2015-12-30T19:20:30"
-L Begin-Row-Number
-N End-Row-Number
-F "Match-Regex-to-Sort-By-Text" : Usually for time like "\d{4}-\d{2}-\d{2}\D\d+:\d+:\d+[\.,]?\d*"
-B "Begin-Text-Regex"
-E "End-Text-Regex"
-s "Sort-by-Regex-(Group1)-or-this" : This will skip lines not matches this Regex, different to -F
-b "Begin-Regex-of-Block-or-Line"
-Q "End-Regex-of-Block"
-q "End-Regex-of-Line"
-H {N} : {N} = 0 to hide output; {N} > 0 to show head N lines; {N} < 0 to skip head N lines.
-T {N} : {N} = 0 to hide output; {N} > 0 to show tail N lines; {N} < 0 to skip tail N lines.
-U 3 -D 3
--colors "Green, t=Red + Yellow_Blue, x = Yellow, e = Cyan_Black, d = Blue, f = Green, p = Green, m = Green, u = Red."
--timeout 30.5
*** ***
More detail/examples see the home doc or just run the exe with '--help' or '-h' or no args.- Method-1: Use
--colorsto set color groups for matching text + file paths + summary.- Full color groups example (explanations see below):
--colors "Green, t=Red+Blue_Yellow+Magenta_Red, x=Yellow, e=Cyan, d=Blue, f=Green, m=Green, u=Yellow"- Valid color names(no-case):
Red + Green + Yellow + Blue + Cyan + Magenta + Black + White + None.
- Full color groups example (explanations see below):
- Method-2: Set environment variable
MSR_COLORSwith value of--colorsexample above.
- Plain text matching(
-x) useYellow(Yellow_None):- Foreground Color =
Yellow - Background Color =
None(usuallyBlack).
- Foreground Color =
- Regex text matching(
-t) use color arrays for Regex-captured-groups:- Linux =
Red_Black + Yellow_Red + White_Magenta + Cyan_Red - Windows =
Red_Black + White_Red + Red_Yellow + White_Magenta
- Linux =
- Regex enhance/extra-coloring (
-e):- Windows =
Green_Black + White_Blue + Black_Cyan + Magenta_Black + Black_White + Yellow_Black - Linux =
Green_Black + White_Blue + Yellow_Blue + Magenta_Black + Black_White + Yellow_Black
- Windows =
- Example:
- Command:
echo abc 123 extra plain | msr -t "\w+ (\d+)" -e "ext\w+" -x plain
- Group -t matched result:
- Output
abcwith colorRed_Black: foreground =Red, background =Black. - Output
123with colorWhite_Red.
- Output
- Group -e matched result:
- Output
extrawith colorGreen_Black.
- Output
- Group -x matched result:
- Output
plainwith colorYellow.
- Output
- Command:
- Change all colors with no group name of
x/t/e:- Example command:
echo abc 123 extra plain | msr -t "\w+ (\d+)" -e "ext\w+" -x plain --colors Green - All matched text of groups
-t/-x/-ewill be output withGreencolor.
- Example command:
- Change one group with group name of
x/t/e:- Example command:
echo abc 123 extra plain | msr -t "\w+ (\d+)" -e "ext\w+" -x plain --colors Green,t=Cyan+Red_Blue - Group -t result use
Cyan + Red_Blue- Output
abcwithCyan. - Output
123withRed_Blue
- Output
- Other matched result of
-x/-euseGreencolor.
- Example command:
- Remove one or more group color:
- Example command:
echo abc 123 extra plain | msr -t "\w+ (\d+)" -e "ext\w+" -x plain --colors t=none - Group -t result will be no color, other groups (
-x/e) keep colors.
- Example command:
- Change result file path color with
d/f/pfordirectory/file-nameorpathfor both.- Example command:
msr -p . -l --colors p=green_blue - Output file paths with color =
Green_Blue(foreground =Green, background =Blue).
- Example command:
- Remove colors for file paths:
- Example command:
msr -p . -l --colors p=none - Output file paths with color =
Nonewhich is no color.
- Example command:
- Change summary color if matched (usually found results):
- Example command:
msr -p . -f "\.cpp$" -t search -x plain-text --colors m=Green.
- Example command:
- Remove summary color whatever matched(
m) or not(u):- Example command:
msr -p . -f "\.cpp$" -t search -x plain-text --colors m=none,u=none.
- Example command:
General example: Transform output to command lines then execute:
echo command line or command output lines | msr -t Search-Regex -o Replace-To -X -P -I -M -A ...
- Hide commands before execution: -P like -X -P or -XP
- Hide return value and time cost: -I like -X -I or -XI
- Hide summary of all executions: -M like -X -M or -XM (-XM or -XMI is mostly used)
- Hide all(command/cost/summary): -A like -XA
- Output
"return-value+command"only if a command returns abnormal code (fail):- Use -X -O to output
"return-value+command"only if a commandreturn != 0. - Use -X -O -V xxx like
-V gt0to output only ifreturn value > 0.
- Use -X -O to output
Brief introduction besides the color doc msr-Color-Doc on Windows as following:
Related controls and options that you can use at the same time:
-
Color Options
- -x
Plain-Text: SetYellowcolor to matchedPlain-Text - -t
Regex-Pattern: SetRedcolor to matchedRegexgroup[0], different group[N] different color. - -e
Regex-Pattern: SetGreencolor to matchedRegexgroup[0], different group[N] different color.- Difference: -e just add colors, -t will add colors + only show matched lines if not used -a.
- -x
-
Auxiliary Controls
- -P: Hide path/line/row.
- -M: Hide summary message.
- -A: No any other info/text. Almost same to combination of -P -M
- -I: Output summary to stderr.
- -a: Show all output lines/text including not matched.
-
Frequently Used Examples
- Only show captured text with color:
- echo
cmd output text| msr -PA -t"Regex, error or need Red color" - echo
cmd output text| msr -PA -x"Plain text, warning or need Yellow color"
- echo
- Show all output: Add color to specific text:
- echo
cmd output text| msr -aPA -t"Regex, error or need Red color.*?(group1) (group2)"-e"extra color (group1) (groupN)" - echo
cmd output text| msr -aPA -x"Plain text, warning or need Yellow color"-e"extra color (group1) (groupN)"
- echo
- More complicate coloring:
- echo
cmd output text| msr -aPA -it"Regex (group1) (group2)"-e"extra (color) (group)"-x"plain text" - echo
cmd output text| msr -PA -it"Regex to only show matched"--nx"exclude text"--nt"exclude Regex" - echo
cmd output text| msr -PA -it"Regex to only show matched with up/down rows, head 100, tail 100"-U 3 -D 9 -H 100 -T 100
- echo
- Only show captured text with color: