Docu review done: Mon 20 Feb 2023 11:05:39 CET
Table of Content
Coloring output
To make use of colors in group you can use the viarbale GREP_COLORS
and the full comamnd is then written like this (if you want to add more colors, set --colors=always
)
GREP_COLORS='mt=01;31' grep "my fancy string"
Samples for color codes
Colorcode | Bold | Color | C&P |
---|---|---|---|
00;30 | [ ] | black | GREP_COLORS='mt=00;30' |
00;37 | [ ] | white | GREP_COLORS='mt=00;37' |
01;30 | [x] | black | GREP_COLORS='mt=01;30' |
01;31 | [x] | red | GREP_COLORS='mt=01;31' |
01;32 | [x] | green | GREP_COLORS='mt=01;32' |
01;33 | [x] | yellow | GREP_COLORS='mt=01;33' |
01;34 | [x] | blue | GREP_COLORS='mt=01;34' |
01;35 | [x] | magenta | GREP_COLORS='mt=01;35' |
01;36 | [x] | cyan | GREP_COLORS='mt=01;36' |
01;37 | [x] | white | GREP_COLORS='mt=01;37' |
Usefull Parameters
Parameter | Description |
---|---|
-o | shows only matchinges |
-l | returns only filename(s) where it matches |
-n | adds the line numbers to the output |
-f <file1> | compares with full content of a file |
Commands
Command | Description |
---|---|
$ grep -E '^ |<string1.. |string2..>' | full output and highlights grep match |
Compare two files
To compare two files based on there content, you can use grep -v -f
to detect missing or changed lines.
Our sampe files test1
:
A0
BB
C8
DD
EE
F1
GG
ZZ
Our sampe files test2
:
B3
DD
EE
G5
CC
AA
FF
XX
You should run the
grep
command against both files to make sure that you dont miss something.
First we will detect changes or missed lines in the file test2
:
$ grep -v -f test1 test2
B3
G5
CC
AA
FF
XX
Based on the result, we know now that the lines above differ or are not part the destination file.
And now the other way round, to make sure that we do not miss non existing lines in file test1
$ grep -v -f test2 test1
A0
BB
C8
F1
GG
ZZ