nkf(1)

πŸ“¦
version 2.1.5 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– nkf β€” the Network Kanji Filter, bestie edition πŸ’–

okay so. <pink>nkf(1)</pink>? That's the manual page for nkf, the Network Kanji Filter. It's a kanji code converter and honestly it's been carrying the whole encoding situation on its back since before we were born. Come sit, I'll walk you through it 🫢


✨ NAME ✨

nkf β€” Network Kanji Filter. That's it, that's the name, iconic, no notes πŸ’…


✨ SYNOPSIS ✨

nkf [-butjnesliohrTVvwWJESZxXFfmMBOcdILg] [file ...]

✨ DESCRIPTION ✨

So <purple>nkf</purple> is yet another kanji code converter between networks, hosts and terminals. Yeah, "yet another", they said it themselves, we're keeping it real. It takes your input kanji code and flips it into whichever kanji code you designate β€” things like ISO-2022-JP, Shift_JIS, EUC-JP, UTF-8, UTF-16 or UTF-32. The range? Immaculate. ✨

One of nkf's most unique faculties β€” and honestly its main character trait β€” is that it guesses the input kanji encodings. It currently recognizes ISO-2022-JP, Shift_JIS, EUC-JP, UTF-8, UTF-16 and UTF-32. So you don't gotta set the input kanji code explicitly. It just knows. πŸ”₯

By default, X0201 kana gets converted into X0208 kana. For X0201 kana, the SO/SI, SSO and ESC-(-I methods are all supported. But heads up: for automatic code detection, nkf assumes there's no X0201 kana in Shift_JIS. If you want to accept X0201 in Shift_JIS, use -X, -x or -S. πŸŽ€

Also, multiple options are specified as separate strings, like this:

print nkf('--ic=UTF8-MAC', '-w', $string), "\n";

…except the last arguments. yeah. that's the rule. πŸ™ˆ


✨ OPTIONS ✨

This is the long part, bestie. Grab a snack. Every single flag is here, I promise. πŸ“

  • -J -S -E -W -W16 -W32 -j -s -e -w -w16 -w32 β€” specify input and output encodings. Upper case is input. cf. --ic and --oc.
    • -J β€” ISO-2022-JP (JIS code).
    • -S β€” Shift_JIS and JIS X 0201 kana. EUC-JP is recognized as X0201 kana. Without the -x flag, JIS X 0201 Katakana (a.k.a. halfwidth kana) is converted into JIS X 0208. If you use Windows, see Windows-31J (CP932).
    • -E β€” EUC-JP.
    • -W β€” UTF-8N.
    • -W16[BL][0] β€” UTF-16. B or L says whether it's Big Endian or Little Endian. 0 says whether to put a BOM or not.
    • -W32[BL][0] β€” UTF-32. B or L says whether it's Big Endian or Little Endian. 0 says whether to put a BOM or not.
  • -b -u β€” output is buffered (this is the DEFAULT), and output is unbuffered. respectively πŸ’…
  • -t β€” no conversion. we're just vibing. no thoughts, head empty, bytes unchanged.
  • -i[@B] β€” specify the escape sequence for JIS X 0208.
    • -i@ β€” use ESC ( @. (JIS X 0208-1978)
    • -iB β€” use ESC ( B. (JIS X 0208-1983/1990 DEFAULT)
  • -o[BJ] β€” specify the escape sequence for US-ASCII/JIS X 0201 Roman. (DEFAULT is B)
  • -r β€” {de/en}crypt ROT13/47. sneaky. love that for us. πŸ•΅οΈ
  • -h[123] --hiragana --katakana --katakana-hiragana
    • -h1 --hiragana β€” Katakana to Hiragana conversion.
    • -h2 --katakana β€” Hiragana to Katakana conversion.
    • -h3 --katakana-hiragana β€” Katakana to Hiragana and Hiragana to Katakana conversion. both directions, greedy, obsessed 😌
  • -T β€” Text mode output (MS-DOS).
  • -f[m [- n]] β€” Folding on m length with n margin in a line. Without this option, fold length is 60 and fold margin is 10.
  • -F β€” New line preserving line folding.
  • -Z[0-3] β€” Convert X0208 alphabet (Fullwidth Alphabets) to ASCII.
    • -Z -Z0 β€” Convert X0208 alphabet to ASCII.
    • -Z1 β€” Convert X0208 kankaku to single ASCII space.
    • -Z2 β€” Convert X0208 kankaku to double ASCII spaces.
    • -Z3 β€” Replacing fullwidth >, <, ", & into '&gt;', '&lt;', '&quot;', '&amp;' as in HTML.
  • -X -x β€” With -X or without this option, X0201 is converted into X0208 Kana. With -x, try to preserve X0208 kana and do not convert X0201 kana to X0208. In JIS output, ESC-(-I is used. In EUC output, SS2 is used.
  • -B[0-2] β€” Assume broken JIS-Kanji input, which lost ESC. Useful when your site is using old B-News Nihongo patch. (ngl that's a whole historical artifact, respect 🫑)
    • -B1 β€” allows any chars after ESC-( or ESC-$.
    • -B2 β€” force ASCII after NL.
  • -I β€” Replacing non iso-2022-jp char into a geta character (substitute character in Japanese). 🩹
  • -m[BQN0] β€” MIME ISO-2022-JP/ISO8859-1 decode. (DEFAULT) To see ISO8859-1 (Latin-1), -l is necessary.
    • -mB β€” Decode MIME base64 encoded stream. Remove header or other part before conversion.
    • -mQ β€” Decode MIME quoted stream. '_' in quoted stream is converted to space.
    • -mN β€” Non-strict decoding. It allows line break in the middle of the base64 encoding.
    • -m0 β€” No MIME decode.
  • -M β€” MIME encode. Header style. All ASCII code and control characters are intact.
    • -MB β€” MIME encode Base64 stream. Kanji conversion is performed before encoding, so this cannot be used as a picture encoder. like, don't try it. it will not eat. πŸ’€
    • -MQ β€” Perform quoted encoding.
  • -l β€” Input and output code is ISO8859-1 (Latin-1) and ISO-2022-JP. -s, -e and -x are not compatible with this option.
  • -L[uwm] -d -c β€” Convert line breaks.
    • -Lu -d β€” unix (LF)
    • -Lw -c β€” windows (CRLF)
    • -Lm β€” mac (CR)

Without this option, nkf doesn't convert line breaks. it minds its business. ✨

  • --fj --unix --mac --msdos --windows β€” Convert for these systems.
  • --jis --euc --sjis --mime --base64 β€” Convert to named code.
  • --jis-input --euc-input --sjis-input --mime-input --base64-input β€” Assume input system.
  • --ic=input codeset --oc=output codeset β€” Set the input or output codeset. NKF supports the following codesets, and those codeset names are case insensitive. πŸ’…
    • ISO-2022-JP β€” a.k.a. RFC1468, 7bit JIS, JUNET
    • EUC-JP (eucJP-nkf) β€” a.k.a. AT&T JIS, Japanese EUC, UJIS
    • eucJP-ascii
    • eucJP-ms
    • CP51932 β€” Microsoft Version of EUC-JP.
    • Shift_JIS β€” a.k.a. SJIS, MS_Kanji
    • Windows-31J β€” a.k.a. CP932
    • UTF-8 β€” same as UTF-8N
    • UTF-8N β€” UTF-8 without BOM
    • UTF-8-BOM β€” UTF-8 with BOM
    • UTF8-MAC (input only) β€” decomposed UTF-8
    • UTF-16 β€” same as UTF-16BE
    • UTF-16BE β€” UTF-16 Big Endian without BOM
    • UTF-16BE-BOM β€” UTF-16 Big Endian with BOM
    • UTF-16LE β€” UTF-16 Little Endian without BOM
    • UTF-16LE-BOM β€” UTF-16 Little Endian with BOM
    • UTF-32 β€” same as UTF-32BE
    • UTF-32BE β€” UTF-32 Big Endian without BOM
    • UTF-32BE-BOM β€” UTF-32 Big Endian with BOM
    • UTF-32LE β€” UTF-32 Little Endian without BOM
    • UTF-32LE-BOM β€” UTF-32 Little Endian with BOM
  • --fb-{skip, html, xml, perl, java, subchar} β€” Specify the way that nkf handles unassigned characters. Without this option, --fb-skip is assumed.
  • --prefix=escape character target character.. β€” When nkf converts to Shift_JIS, nkf adds a specified escape character to specified 2nd byte of Shift_JIS characters. The 1st byte of the argument is the escape character and following bytes are target characters.
  • --no-cp932ext β€” Handle the characters extended in CP932 as unassigned characters.
  • --no-best-fit-chars β€” When Unicode to Encoded byte conversion, don't convert characters which is not round trip safe. When Unicode to Unicode conversion, with this and the -x option, nkf can be used as UTF converter. (In other words, without this and -x option, nkf doesn't save some characters.)

When nkf converts strings that related to path, you should use this option. 🫢

  • --cap-input β€” Decode hex encoded characters.
  • --url-input β€” Unescape percent escaped characters.
  • --numchar-input β€” Decode character reference, such as "&#....;".
  • --in-place[=SUFFIX] --overwrite[=SUFFIX] β€” Overwrite original listed files by filtered result.
Note: --overwrite preserves timestamps of original files. ⏰
  • --guess=[12] β€” Print guessed encoding and newline. (2 is default, 1 is only encoding)
  • --help β€” Print nkf's help.
  • --version β€” Print nkf's version.
  • -- β€” Ignore rest of -option.

✨ AUTHOR ✨

Copyright (c) 1987, Fujitsu LTD. (Itaru ICHIKAWA).

Copyright (c) 1996-2018, The nkf Project.


and that's the whole page, bestie!! πŸ’– you made it, you absolute legend, main character energy fr fr. go forth and convert some kanji, slay βœ¨πŸ¦‹πŸŒΈ

this has been nkf 2.1.5, dated 2018-12-15, and yeah the manual is literally just called nkf(1). bye bestie!! πŸŽ€πŸ‘‘πŸ’œ