Skip to Content
プログラミング言語AWK 第2版
book

プログラミング言語AWK 第2版

by Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger, 千住 治郎
May 2024
Intermediate to advanced
276 pages
3h 51m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミング言語AWK 第2版

5章レポートとデータベース

本章では、データファイルからの情報抽出とレポート生成について述べる。扱うのは表形式のデータばかりだが、手法自体はもっと複雑な形式にも応用できる。本章の主眼は、協調動作し、密接な関係を持つプログラム群の実装にある。一度処理するだけでは目的に辿り着けないが、複数回処理することで解決が容易になるデータ処理の例を多数取り上げる。

本章は単一データファイルからのレポート生成から始める。レポートの最終的な見せ方も重要だが、データファイルのスキャンにも注意が必要だ。その後、相互に関係する複数ファイルに記述されたデータを扱う方法へ進む。ここでは、一連のデータファイルをリレーショナルデータベースと捉え、汎用的なアプローチを採る。利点は他にもあるが、数値ではなく名前を用いフィールドを参照できる利点が挙げられる。

5.1レポートの生成

Awk はデータファイルから情報を抽出し、書式を用い、レポートにまとめるのが得意だ。レポートに限らず、なんらかのアクティビティをまとめた「ダッシュボード」も生成できる。ここではこの生成を、準備 (prepare)、ソート (sort)、書式を用いた整形 (format) の 3 段階に分けて考える。

「準備」ではデータを選択する。目的の情報を得るためなんらかの計算処理をすることもあるだろう。「ソート」は、出力する情報を特定の順序で並べる場合に必要な作業だ。ここでは「準備」作業の出力をシステムの sort コマンドに渡すこととする。最後の「整形」作業は Awk プログラムをもう 1 つ用い、ソートしたデータを目的の書式で出力する。

単純レポート

使用するデータは以下に示す countries というファイルだ。

Russia 16376 145 Europe ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

プログラミングRust 第2版

プログラミングRust 第2版

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall, 中田 秀基
仕事ではじめる機械学習 第2版

仕事ではじめる機械学習 第2版

有賀 康顕, 中山 心太, 西林 孝
詳説 イーサネット 第2版

詳説 イーサネット 第2版

Charles E. Spurgeon, Joann Zimmerman, 三浦 史光, 豊沢 聡
Linuxカーネルプログラミング 第2版

Linuxカーネルプログラミング 第2版

Kaiwan N. Billimoria, 武内 覚, 大岩 尚宏

Publisher Resources

ISBN: 9784814400706Publisher Website