команда файла, по-видимому, возвращая неправильный тип MIME

grep использованием по умолчанию BREs, таким образом, необходимо выйти круглых скобок:

grep 'AB\{4\}'
grep '\(AB\)\{4\}'

Можно также использовать EREs путем передачи -E опция, доступная на некоторых grep реализациях:

grep -E 'AB{4}'
grep -E '(AB){4}'
6
17.02.2015, 23:30
2 ответа

К сожалению, вероятно, вы ничего не можете сделать, чтобы сделать файл создавать правильный выход.

Команда файл тестирует первые несколько байтов файла против базы данных магических чисел. Это легко проверить в двоичных файлах (например, изображения или исполняемые файлы), которые имеют некоторые конкретные идентификаторы в начале файла.

Если файл не является двоичным файлом, он проверит кодировку, а также искать некоторые конкретные слова в файле, чтобы определить тип, но только для ограниченного количества типов файлов (большинство из которых являются языками программирования) Отказ

5
27.01.2020, 20:24

Миметипы определяются тем, что по эмблему Unix называется «волшебные числа». В каждом файле есть волшебный номер, который определяет тип файла и формат файла. Экстракт ниже из файловых командных страниц

The magic number tests are used to check for files with data in partic-
       ular fixed formats.  The canonical example of this  is  a  binary  exe-
       cutable  (compiled  program)  a.out  file,  whose  format is defined in
       a.out.h and possibly exec.h in the standard include  directory.   These
       files  have  a  'magic  number'  stored  in a particular place near the
       beginning of the file that tells the UNIX  operating  system  that  the
       file  is  a binary executable, and which of several types thereof.  The
       concept of 'magic number' has been applied by extension to data  files.
       Any  file  with  some invariant identifier at a small fixed offset into
       the file can usually be described in this way.  The information identi-
       fying   these   files   is   read   from   the   compiled   magic  file
       /usr/share/file/magic.mgc , or  /usr/share/file/magic  if  the  compile
       file  does  not exist. In addition file will look in $HOME/.magic.mgc ,
       or $HOME/.magic for magic entries.

Страницы Man Unix также упомянули, что если файл не соответствует волшебным номерам, текстовый файл считается ASCII / ISO-8859-X / Non-ISO 8-битный расширенный -Ascii (Best Supletized Format)

 If a file does not match any of the entries in the magic    file,  it  is
       examined to see if it seems to be a text file.  ASCII, ISO-8859-x, non-
       ISO 8-bit extended-ASCII character sets (such as those used  on  Macin-
       tosh  and  IBM  PC systems), UTF-8-encoded Unicode, UTF-16-encoded Uni-
       code, and EBCDIC character sets can be distinguished by  the  different
       ranges  and  sequences  of bytes that constitute printable text in each
       set.  If a file passes  any  of  these  tests,  its  character  set  is
       reported.  ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are iden-
       tified as ''text'' because they will be mostly readable on  nearly  any
       terminal

Предложение

Используйте команду Mimetype вместо команды файла

mimetype temp.csv

веб-ссылка для дальнейшего копания

http://unixhelp.ed.ac.uk/CGI/man-cgi?file
6
27.01.2020, 20:24

Теги

Похожие вопросы