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版

4章データ処理

元々 Awk は、ここまでの 3章で述べたような情報の抽出、データ検証、変形、要約など、日々のデータ処理を目的に開発したものだ。本章でもデータ処理という方向性は変わらないが、さらに複雑な内容に取り組む。例示するものの大半は通常の 1 行ずつの処理だが、「4.4 マルチラインレコード」では複数行にまたがる入力データの取り扱い方を述べる。

Awk プログラムは追加的に実装することが多い。プログラムの数行を書いてはテストし、さらに数行を追加しては再テストという作業を繰り返す。本書のプログラムでも、ある程度の大きさのものはそのように実装した。

もちろん古典的な手法でも Awk プログラムは開発できる。プログラムの基本設計から始め、言語マニュアルを確認しながら設計を深めて行く手法だ。しかし、既存のプログラムを目的に合わせて改造して行く方がずっと容易なことが多い。本書で例示するプログラムも、この手法の出発点となるだろう。

4.1データの変形とリダクション

データの形式変換は Awk でもっとも多い用途の 1 つだ。あるプログラムの出力を別のプログラムへ渡す際に、その形式を変換する用途だ。もう 1 つの用途に、大規模データ内の必要部分の選択がある。この場合は書式を変更したり、後の集計用に情報を付加することが多い。本節ではこれらのさまざまな例を提示する。

フィールド別の集計

ここまで、特定フィールドの値を合計する短い Awk プログラムをいくつも提示した。「2.4 データ要約」ではフィールド別に値を合計する addup プログラムを示したが、これは入力フィールドを何も検査しなかった。次に取り上げるプログラムは多少複雑になるが、やはり典型的なリダクション処理だ。すなわち、入力行にはフィールドが複数あり、フィールドはそれぞれ数値を持ち、フィールドがいくつあるかに関わらずフィールド別の合計値を求める。 ...

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