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版

1章Awkチュートリアル

Awk は計算やデータ操作に幅広く利用できる、有用かつ表現力に優れたプログラミング言語だ。本章は、読者ができるだけ早く自分のプログラムを書き始められることを念頭に構成したチュートリアルだ。さまざまな分野の問題を Awk ではどのように解決できるかを示すのは以降の章に譲る。言語全体を詳細に記したリファレンスマニュアルは「付録 A:Awk リファレンスマニュアル」に収録してある。本書では全体を通じ、読者が楽しみながら学べるよう、有用かつ示唆に富んだ例題を取り上げた。

1.1さあ始めよう

Awk ではほんの 1、2 行の短いプログラムでも役立つものが多い。ここで、従業員の情報を書いたファイル emp.data があるとしよう。内容は、1 行ごとに従業員の名前、時間給 (ドル)、労働時間の 3 つの情報を、タブまたは空白で区切った次のようなものだ。

Beth    21      0
Dan     19      0
Kathy   15.50   10
Mark    25      20
Mary    22.50   22
Susie   17      18

このファイルから、1 時間以上働いた者全員の名前と賃金 (時間給と労働時間の積) を得たいとする。Awk はまさにこのような処理向けに開発された言語であり、きわめて容易に表現できる。コマンドラインに次の 1 行を入力する (コマンドプロンプトを $ とする)。

$ awk '$3 > 0 { print $1, $2 * $3 }' emp.data

次の出力が得られる。

Kathy 155
Mark 500
Mary 495
Susie 306

入力したコマンドに従い、システムは Awk を起動する。Awk が解釈、実行するのは続くクォーテーションマークで囲んだプログラムであり、このプログラムには ...

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