Closed5

AL2023インスタンスでテキストファイルのgrepがバイナリ判定される

Junichi HashimotoJunichi Hashimoto

AL2023インスタンスでのみテキストファイルがバイナリ判定される。

grep "foo" example.txt
# grep: example.txt: binary file matches
Junichi HashimotoJunichi Hashimoto

v2.21でバイナリ判定基準が変更されたため。

https://cgit.git.savannah.gnu.org/cgit/grep.git/tree/NEWS?h=v2.21

* Noteworthy changes in release 2.21 (2014-11-23) [stable]

** Improvements

...

  If a file contains data improperly encoded for the current locale,
  and this is discovered before any of the file's contents are output,
  grep now treats the file as binary.

リリース 2.21 (2014-11-23) [stable] の注目すべき変更点

改善点

ファイルが現在のロケールに対して不正にエンコードされたデータを含み、それがファイル内容を出力する前に検出された場合、grep はそのファイルをバイナリファイルとして扱うようになりました。

Junichi HashimotoJunichi Hashimoto

対策。-a, --text, --binary-files=textのいずれかのオプションを付ける。

grep --help | grep 'binary\-files'
      --binary-files=TYPE   assume that binary files are TYPE;
  -a, --text                equivalent to --binary-files=text
このスクラップは3日前にクローズされました