It is necessary to find all the files that contain a specific string. I usually do this:

grep -rl 'Текст' /path/to/dir 

however, now it was necessary to search the files in cp1251 encoding. The old version no longer works. How to do?

  • one
    For this, I use LANG=ru_RU.CP1251 grep -rl 'Текст' /path/to/dir , the terminal settings should be CP1251. For example, in Gnome Terminal or Putty this can be done in a couple of clicks. - chernomyrdin

1 answer 1

The solution was found:

 find path/to/dir/ -exec grep -il "`echo 'Текст'|iconv -f utf8 -t cp1251`" '{}' \; > result.txt 
  • In the comments from @chernomyrdin, the solution is better (much more efficient). When redirecting output to a file about the terminal settings, of course you can not worry. - avp
  • Actually, changing the settings of the terminal to solve one problem, in my opinion, is not a very good solution. And what if you have to run this script without X's? - skegg