If the encoding of all the files is the same, you just need to write the searched sentence in that encoding. That brings up two possible conditions:
The encoding on the command line (or where the command is executed) (probably set by one of the locale
variables LC_*
) is the same as the encoding of all the files, then, just grep as usual:
grep -rn 'KORONAVÍRUS, obmedzená.'
Use the -w
option only if you want to match the whole line.
If the encoding of all files is different, change the search string to that encoding.
$ echo 'KORONAVÍRUS, obmedzená.' >orig
$ grep -ran "$(cat orig | iconv -t CP1252)"
Here, the -a
option allows grep to search inside files with diferent encodings that may be detected as binary
.
If the files could contain different encodings then there is no solution possible. There is no way to auto-detect a file encoding.
It is not possible to search inside a list of files if the files doesn't have an uniform encoding.
Related:
How to use grep/ack with files in arbitrary encoding?
KORONAV[[=I=]]RUS
– steeldriver May 12 '20 at 21:01.
will fail, as the "any character" has to be a character valid in the encoding being used to run the command. – May 12 '20 at 21:54