LinuxCommandLibrary

preconv

Convert file contents to specified encoding

SYNOPSIS

preconv [options] [file]

PARAMETERS

-h, --help
    Display help message and exit.

-V, --version
    Display version information and exit.

-q, --quiet
    Suppress all messages. No errors, warnings or notices will be displayed.

-r, --recode-kcc
    Recode Korean character set when input encoding is 'kcc'.

-x ENCODING, --exec-charset=ENCODING
    Specify the execution character set (used for temporary files and pipe redirections). Default is UTF-8 if the locale supports it, otherwise ASCII.

-t TEMPORARY_DIRECTORY, --temp-directory=TEMPORARY_DIRECTORY
    Specify temporary directory to store files while processing. Default is specified by the environment variables $TMPDIR, $TEMP, or $TMP; or if none of those are defined, the /tmp directory.

-i ENCODING, --input-encoding=ENCODING
    Specify input encoding. If not provided, encoding will attempt to be guessed.

-w, --warn
    Enable warnings when conversion errors occur. By default, errors are ignored.

DESCRIPTION

preconv converts the content of a file to a specified encoding before passing it to another program. This is particularly useful when dealing with input files that might have different encodings, ensuring consistent processing.

It acts as a filter, reading from standard input or a specified file, converting the text based on specified or automatically detected input encoding, and writing the result to standard output.

The primary purpose is to handle character encoding conversions automatically, especially in situations where the receiving program expects a specific encoding and cannot handle other encodings directly. iconv is used for the underlying encoding conversion.

CAVEATS

Automatic encoding detection is not always reliable, especially for short files or files with ambiguous character sequences. Specifying the input encoding manually is generally recommended for predictable behavior.

FILE ARGUMENT

If no file is specified, preconv reads from standard input.

EXAMPLES

preconv -i ISO-8859-1 my_file.txt | less: Converts my_file.txt from ISO-8859-1 to the locale encoding and pipes it to less.
preconv < my_file.txt > output.txt: Converts my_file.txt from an automatically detected encoding to the locale encoding and writes the output to output.txt.

SEE ALSO

iconv(1), recode(1)

Copied to clipboard