Bab 11. Konversi data

Daftar Isi

11.1. Alat konversi data teks
11.1.1. Mengonversi berkas teks dengan iconv
11.1.2. Memeriksa berkas apakah UTF-8 dengan iconv
11.1.3. Mengonversi nama berkas dengan iconv
11.1.4. Konversi EOL
11.1.5. Konversi TAB
11.1.6. Editors with auto-conversion
11.1.7. Ekstraksi teks polos
11.1.8. Menyoroti dan memformat data teks polos
11.2. Data XML
11.2.1. Petunjuk dasar untuk XML
11.2.2. Pemrosesan XML
11.2.3. Ekstraksi data XML
11.2.4. Lint data XML
11.3. Type setting
11.3.1. roff typesetting
11.3.2. TeX/LaTeX
11.3.3. Mencetak cantik halaman manual
11.3.4. Membuat halaman manual
11.4. Data yang dapat dicetak
11.4.1. Ghostscript
11.4.2. Menggabungkan dua berkas PS atau PDF
11.4.3. Utilitas data yang dapat dicetak
11.4.4. Mencetak dengan CUPS
11.5. Konversi data surat
11.5.1. Dasar-dasar data surel
11.6. Alat data grafis
11.7. Konversi data lain-lain

Tools and tips for converting data formats on the Debian system are described.

Standard based tools are in very good shape but support for proprietary data formats are limited.

Paket-paket berikut untuk konversi data teks menarik perhatian saya.


[Tip] Tip

iconv(1) disediakan sebagai bagian dari paket libc6 dan selalu tersedia di hampir semua sistem mirip Unix untuk mengonversi pengodean karakter.

Anda dapat mengonversi pengodean berkas teks dengan iconv(1) dengan yang berikut ini.

$ iconv -f encoding1 -t encoding2 input.txt >output.txt

Nilai pengodean tidak membedakan huruf besar kecil dan mengabaikan "-" dan "_" untuk pencocokkan. Pengodean yang didukung dapat diperiksa oleh perintah "iconv -l".


[Catatan] Catatan

Beberapa pengodean hanya didukung untuk konversi data dan tidak digunakan sebagai nilai lokal (Bagian 8.1, “Lokal”).

Untuk set karakter yang masuk dalam byte tunggal seperti set karakter ASCII dan ISO-8859, pengodean karakter berarti hampir sama dengan set karakter.

Untuk set karakter dengan banyak karakter seperti JIS X 0213 untuk Jepang atau Universal Character Set (UCS, Unicode, ISO-10646-1) untuk hampir semua bahasa, ada banyak skema pengodean yang sesuai dengan mereka ke dalam urutan data byte.

Untuk ini, ada diferensiasi yang jelas antara set karakter dan pengodean karakter.

Code page digunakan sebagai sinonim untuk tabel pengodean karakter untuk beberapa vendor tertentu.

[Catatan] Catatan

Please note most encoding systems share the same code with ASCII for the 7 bit characters. But there are some exceptions. If you are converting old Japanese C programs and URLs data from the casually-called shift-JIS encoding format to UTF-8 format, use "CP932" as the encoding name instead of "shift-JIS" to get the expected results: 0x5C → "\" and 0x7E → "~". Otherwise, these are converted to wrong characters.

[Tip] Tip

recode(1) may be used too and offers more than the combined functionality of iconv(1), fromdos(1), todos(1), frommac(1), and tomac(1). For more, see "info recode".

Intelligent modern editors such as the vim program are quite smart and copes well with any encoding systems and any file formats. You should use these editors under the UTF-8 locale in the UTF-8 capable console for the best compatibility.

An old western European Unix text file, "u-file.txt", stored in the latin1 (iso-8859-1) encoding can be edited simply with vim by the following.

$ vim u-file.txt

This is possible since the auto detection mechanism of the file encoding in vim assumes the UTF-8 encoding first and, if it fails, assumes it to be latin1.

An old Polish Unix text file, "pu-file.txt", stored in the latin2 (iso-8859-2) encoding can be edited with vim by the following.

$ vim '+e ++enc=latin2 pu-file.txt'

An old Japanese unix text file, "ju-file.txt", stored in the eucJP encoding can be edited with vim by the following.

$ vim '+e ++enc=eucJP ju-file.txt'

An old Japanese MS-Windows text file, "jw-file.txt", stored in the so called shift-JIS encoding (more precisely: CP932) can be edited with vim by the following.

$ vim '+e ++enc=CP932 ++ff=dos jw-file.txt'

When a file is opened with "++enc" and "++ff" options, ":w" in the Vim command line stores it in the original format and overwrite the original file. You can also specify the saving format and the file name in the Vim command line, e.g., ":w ++enc=utf8 new.txt".

Please refer to the mbyte.txt "multi-byte text support" in vim on-line help and Tabel 11.2, “Daftar nilai pengodean dan penggunaannya” for locale values used with "++enc".

The emacs family of programs can perform the equivalent functions.

Extensible Markup Language (XML) adalah bahasa markup untuk dokumen yang berisi informasi terstruktur.

Lihat informasi pengantar di XML.COM.

Teks XML terlihat agak mirip HTML. Ini memungkinkan kita untuk mengelola beberapa format keluaran untuk dokumen. Salah satu sistem XML yang mudah adalah paket docbook-xsl, yang digunakan di sini.

Setiap berkas XML dimulai dengan deklarasi XML standar sebagai berikut.

<?xml version="1.0" encoding="UTF-8"?>

Sintaks dasar untuk satu elemen XML ditandai sebagai berikut.

<name attribute="value">content</name>

Elemen XML dengan konten kosong ditandai dalam bentuk pendek berikut.

<name attribute="value" />

"attribute="nilai"" dalam contoh di atas adalah opsional.

Bagian komentar dalam XML ditandai sebagai berikut.

<!-- comment -->

Selain menambahkan markup, XML memerlukan konversi kecil ke konten menggunakan entitas terpradefinisi untuk karakter-karakter berikut.


[Perhatian] Perhatian

"<" atau "&" tidak dapat digunakan dalam atribut atau elemen.

[Catatan] Catatan

Ketika entitas tentuan pengguna gaya SGML, misalnya "&tag-anu;", digunakan, definisi pertama menang atas yang lain. Definisi entitas dinyatakan dalam "<!ENTITY tag-anu "entity value">".

[Catatan] Catatan

Selama markup XML dilakukan secara konsisten dengan set tertentu dari nama tag (baik beberapa data sebagai konten atau nilai atribut), konversi ke XML lain adalah tugas sepele menggunakan Extensible Stylesheet Language Transformations (XSLT).

Ada banyak alat yang tersedia untuk memproses berkas XML seperti Extensible Stylesheet Language (XSL).

Pada dasarnya, setelah Anda membuat berkas XML yang terbentuk dengan baik, Anda dapat mengonversinya ke format apa pun menggunakan Extensible Stylesheet Language Transformations (XSLT).

Extensible Stylesheet Language for Formatting Objects (XSL-FO) seharusnya menjadi solusi untuk pemformatan. Paket fop baru di arsip main Debian karena ketergantungannya pada bahasa pemrograman Java. Jadi kode LaTeX biasanya dihasilkan dari XML menggunakan XSLT dan sistem LaTeX digunakan untuk membuat berkas yang dapat dicetak seperti DVI, PostScript, dan PDF.


Karena XML adalah bagian dari Standard Generalized Markup Language (SGML), itu dapat diproses oleh alat yang banyak tersedia untuk SGML, seperti Document Style Semantics and Specification Language (DSSSL).


[Tip] Tip

GNOME yelp kadang-kadang berguna untuk membaca berkas XML Docbook secara langsung karena itu merender secara layak pada X.

The Unix troff program originally developed by AT&T can be used for simple typesetting. It is usually used to create manpages.

TeX created by Donald Knuth is a very powerful type setting tool and is the de facto standard. LaTeX originally written by Leslie Lamport enables a high-level access to the power of TeX.


Secara tradisional, roff adalah sistem pemrosesan teks Unix utama. Lihat roff(7), groff(7), groff(1), grotty(1), troff(1), groff_mdoc(7), groff_man(7), groff_ms(7), groff_me(7), groff_mm(7), dan "info groff".

Anda dapat membaca atau mencetak tutorial dan referensi yang bagus tentang "-me" makro di "/usr/share/doc/groff/" dengan memasang paket groff.

[Tip] Tip

"groff -Tascii -me -" menghasilkan keluaran teks polos dengan kode escape ANSI. Jika Anda ingin mendapatkan keluaran mirip manpage dengan banyak "^H" dan "_", gunakan "GROFF_NO_SGR=1 groff -Tascii -me -" sebagai gantinya.

[Tip] Tip

Untuk menghapus "^H" dan "_" dari berkas teks yang dihasilkan oleh groff, filter dengan "col -b -x".

Distribusi perangkat lunak TeX Live menawarkan sistem TeX yang lengkap. Metapackage texlive menyediakan pilihan yang layak dari paket TeX Live yang seharusnya cukup untuk tugas yang paling umum.

Ada banyak referensi yang tersedia untuk TeX dan LaTeX.

  • The teTeX HOWTO: The Linux-teTeX Local Guide

  • tex(1)

  • latex(1)

  • texdoc(1)

  • texdoctk(1)

  • "The TeXbook", by Donald E. Knuth, (Addison-Wesley)

  • "LaTeX - A Document Preparation System", by Leslie Lamport, (Addison-Wesley)

  • "The LaTeX Companion", by Goossens, Mittelbach, Samarin, (Addison-Wesley)

This is the most powerful typesetting environment. Many SGML processors use this as their back end text processor. Lyx provided by the lyx package and GNU TeXmacs provided by the texmacs package offer nice WYSIWYG editing environment for LaTeX while many use Emacs and Vim as the choice for the source editor.

There are many online resources available.

When documents become bigger, sometimes TeX may cause errors. You must increase pool size in "/etc/texmf/texmf.cnf" (or more appropriately edit "/etc/texmf/texmf.d/95NonPath" and run update-texmf(8)) to fix this.

[Catatan] Catatan

The TeX source of "The TeXbook" is available at http://tug.ctan.org/tex-archive/systems/knuth/dist/tex/texbook.tex. This file contains most of the required macros. I heard that you can process this document with tex(1) after commenting lines 7 to 10 and adding "\input manmac \proofmodefalse". It's strongly recommended to buy this book (and all other books from Donald E. Knuth) instead of using the online version but the source is a great example of TeX input!

Printable data is expressed in the PostScript format on the Debian system. Common Unix Printing System (CUPS) uses Ghostscript as its rasterizer backend program for non-PostScript printers.

You can merge two PostScript (PS) or Portable Document Format (PDF) files using gs(1) of Ghostscript.

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pswrite -sOutputFile=bla.ps -f foo1.ps foo2.ps
$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=bla.pdf -f foo1.pdf foo2.pdf
[Catatan] Catatan

The PDF, which is a widely used cross-platform printable data format, is essentially the compressed PS format with few additional features and extensions.

[Tip] Tip

For command line, psmerge(1) and other commands from the psutils package are useful for manipulating PostScript documents. pdftk(1) from the pdftk package is useful for manipulating PDF documents, too.

Both lp(1) and lpr(1) commands offered by Common Unix Printing System (CUPS) provides options for customized printing the printable data.

You can print 3 copies of a file collated using one of the following commands.

$ lp -n 3 -o Collate=True filename
$ lpr -#3 -o Collate=True filename

You can further customize printer operation by using printer option such as "-o number-up=2", "-o page-set=even", "-o page-set=odd", "-o scaling=200", "-o natural-scaling=200", etc., documented at Command-Line Printing and Options.

The following packages for the mail data conversion caught my eyes.


[Tip] Tip

The Internet Message Access Protocol version 4 (IMAP4) server may be used to move mails out from proprietary mail systems if the mail client software can be configured to use IMAP4 server too.

Mail (SMTP) data should be limited to series of 7 bit data. So binary data and 8 bit text data are encoded into 7 bit format with the Multipurpose Internet Mail Extensions (MIME) and the selection of the charset (see Tabel 11.2, “Daftar nilai pengodean dan penggunaannya”).

The standard mail storage format is mbox formatted according to RFC2822 (updated RFC822). See mbox(5) (provided by the mutt package).

For European languages, "Content-Transfer-Encoding: quoted-printable" with the ISO-8859-1 charset is usually used for mail since there are not much 8 bit characters. If European text is encoded in UTF-8, "Content-Transfer-Encoding: quoted-printable" is likely to be used since it is mostly 7 bit data.

For Japanese, traditionally "Content-Type: text/plain; charset=ISO-2022-JP" is usually used for mail to keep text in 7 bits. But older Microsoft systems may send mail data in Shift-JIS without proper declaration. If Japanese text is encoded in UTF-8, Base64 is likely to be used since it contains many 8 bit data. The situation of other Asian languages is similar.

[Catatan] Catatan

If your non-Unix mail data is accessible by a non-Debian client software which can talk to the IMAP4 server, you may be able to move them out by running your own IMAP4 server.

[Catatan] Catatan

If you use other mail storage formats, moving them to mbox format is the good first step. The versatile client program such as mutt(1) may be handy for this.

You can split mailbox contents to each message using procmail(1) and formail(1).

Each mail message can be unpacked using munpack(1) from the mpack package (or other specialized tools) to obtain the MIME encoded contents.

The following packages for the graphic data conversion, editing, and organization tools caught my eyes.

Tabel 11.17. Daftar alat data grafis

paket popcon ukuran kata kunci deskripsi
gimp V:61, I:300 19827 gambar(bitmap) GNU Image Manipulation Program
imagemagick I:353 221 gambar(bitmap) program manipulasi gambar
graphicsmagick V:2, I:15 5306 gambar(bitmap) program manipulasi citra (fork dari imagemagick)
xsane V:16, I:161 2346 gambar(bitmap) GTK-based X11 frontend for SANE (Scanner Access Now Easy)
netpbm V:28, I:363 5056 gambar(bitmap) alat konversi grafis
icoutils V:12, I:82 221 png↔ico(bitmap) convert MS Windows icons and cursors to and from PNG formats (favicon.ico)
scribus V:2, I:22 30523 ps/pdf/SVG/… Penyunting DTP Scribus
libreoffice-draw V:119, I:427 13442 gambar(vector) LibreOffice office suite - drawing
inkscape V:35, I:167 87324 gambar(vector) Penyunting SVG (Scalable Vector Graphics)
dia V:3, I:28 3620 gambar(vector) penyunting diagram (Gtk)
xfig V:1, I:14 6334 gambar(vector) Facility for Interactive Generation of figures under X11
pstoedit V:3, I:76 1003 ps/pdf→gambar(vector) Konverter berkas PostScript dan PDF ke grafis vektor yang dapat disunting (SVG)
libwmf-bin V:8, I:176 180 Windows/gambar(vector) Alat konversi metafile Windows (data grafik vektor)
fig2sxd V:0, I:0 149 fig→sxd(vector) mengonversi berkas XFig ke format OpenOffice.org Draw
unpaper V:2, I:19 460 gambar→gambar alat pasca-pemrosesan bagi halaman yang dipindai untuk OCR
tesseract-ocr V:8, I:36 1507 gambar→text perangkat lunak OCR bebas berdasarkan mesin OCR komersial HP
tesseract-ocr-eng V:6, I:37 4032 gambar→text Data mesin OCR: berkas bahasa tesseract-ocr untuk teks bahasa Inggris
gocr V:1, I:10 531 gambar→text perangkat lunak OCR bebas
ocrad V:0, I:4 318 gambar→text perangkat lunak OCR bebas
eog V:64, I:269 7640 gambar(Exif) Program penampil grafis Eye of GNOME
gthumb V:4, I:20 5318 gambar(Exif) penampil dan peramban citra (GNOME)
geeqie V:5, I:18 15785 gambar(Exif) penampil citra menggunakan GTK
shotwell V:17, I:237 6402 gambar(Exif) pengorganisasi foto digital (GNOME)
gtkam V:0, I:5 1154 gambar(Exif) aplikasi untuk mengambil media dari kamera digital (GTK)
gphoto2 V:0, I:11 955 gambar(Exif) Klien baris perintah kamera digital gphoto2
gwenview V:27, I:94 11042 gambar(Exif) penampil citra (KDE)
kamera I:94 854 gambar(Exif) dukungan kamera digital untuk aplikasi KDE
digikam V:2, I:12 2921 gambar(Exif) aplikasi manajemen foto digital untuk KDE
exiv2 V:2, I:36 305 gambar(Exif) alat manipulasi metadata EXIF/IPTC
exiftran V:1, I:18 70 gambar(Exif) mentransformasi citra jpeg kamera digital
jhead V:0, I:10 131 gambar(Exif) memanipulasi bagian non-gambar dari berkas JPEG patuh Exif (foto kamera digital)
exif V:1, I:16 339 gambar(Exif) utilitas baris perintah untuk menampilkan informasi EXIF dalam berkas JPEG
exiftags V:0, I:4 292 gambar(Exif) utility to read Exif tags from a digital camera JPEG file
exifprobe V:0, I:4 499 gambar(Exif) membaca metadata dari gambar digital
dcraw V:2, I:16 562 gambar(Raw)→ppm decode raw digital camera images
findimagedupes V:0, I:1 82 image→fingerprint menemukan gambar yang serupa secara visual atau duplikat
ale V:0, I:0 839 gambar→gambar menggabung gambar untuk meningkatkan mutu atau membuat mosaik
imageindex V:0, I:2 145 gambar(Exif)→html menghasilkan galeri HTML statis dari gambar
outguess V:0, I:2 231 jpeg,png alat Steganografi universal
librecad V:2, I:16 8309 DXF Penyunting data CAD (KDE)
blender V:3, I:36 85549 blend, TIFF, VRML, … Penyunting konten 3D untuk animasi dll
mm3d V:0, I:0 3868 ms3d, obj, dxf, … Penyunting model 3D berbasis OpenGL
open-font-design-toolkit I:0 10 ttf, ps, … metapackage untuk desain fonta terbuka
fontforge V:0, I:7 4191 ttf, ps, … penyunting fonta untuk fonta PS, TrueType, dan OpenType
xgridfit V:0, I:0 806 ttf program for gridfitting and hinting TrueType fonts

[Tip] Tip

Cari lebih banyak alat gambar menggunakan regex "~Gworks-with::image" dalam aptitude(8) (lihat Bagian 2.2.6, “Opsi metode pencarian dengan aptitude”).

Although GUI programs such as gimp(1) are very powerful, command line tools such as imagemagick(1) are quite useful for automating image manipulation via scripts.

The de facto image file format of the digital camera is the Exchangeable Image File Format (EXIF) which is the JPEG image file format with additional metadata tags. It can hold information such as date, time, and camera settings.

The Lempel-Ziv-Welch (LZW) lossless data compression patent has been expired. Graphics Interchange Format (GIF) utilities which use the LZW compression method are now freely available on the Debian system.

[Tip] Tip

Any digital camera or scanner with removable recording media works with Linux through USB storage readers since it follows the Design rule for Camera Filesystem and uses FAT filesystem. See Bagian 10.1.7, “Perangkat penyimpanan lepasan”.

Ada banyak program lain untuk mengonversi data. Paket-paket berikut menarik perhatian saya menggunakan regex "~Guse::converting" dalam aptitude(8) (lihat Bagian 2.2.6, “Opsi metode pencarian dengan aptitude”).


You can also extract data from RPM format with the following.

$ rpm2cpio file.src.rpm | cpio --extract