Unix: Check File is UTF-8 Encoding or Not

Contents

  1. Example
  2. References
 
iconv -f utf-8 -t ucs-4 < myfile >/dev/null
# No error means utf-8 encoding
# Error means NOT utf-8 encoding

Example

$ iconv -f utf-8 -t ucs-4 < utf8_file >/dev/null
$ iconv -f utf-8 -t ucs-4 < non_utf8_file >/dev/null
iconv: conversion error
Conversion error detected while processing stdin.

References

* How can I be sure of the file encoding?

This entry was posted in Uncategorized. Bookmark the permalink.