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

ColorcodeBoldColorC&P
00;30[ ]blackGREP_COLORS='mt=00;30'
00;37[ ]whiteGREP_COLORS='mt=00;37'
01;30[x]blackGREP_COLORS='mt=01;30'
01;31[x]redGREP_COLORS='mt=01;31'
01;32[x]greenGREP_COLORS='mt=01;32'
01;33[x]yellowGREP_COLORS='mt=01;33'
01;34[x]blueGREP_COLORS='mt=01;34'
01;35[x]magentaGREP_COLORS='mt=01;35'
01;36[x]cyanGREP_COLORS='mt=01;36'
01;37[x]whiteGREP_COLORS='mt=01;37'

Usefull Parameters

ParameterDescription
-oshows only matchinges
-lreturns only filename(s) where it matches
-nadds the line numbers to the output
-f <file1>compares with full content of a file

Commands

CommandDescription
$ 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