Skip to Content
マスタリングLinuxシェルスクリプト 第2版 ―Linuxコマンド、bashスクリプト、シェルプログラミング実践入門
book

マスタリングLinuxシェルスクリプト 第2版 ―Linuxコマンド、bashスクリプト、シェルプログラミング実践入門

by Mokhtar Ebrahim, Andrew Mallett, 萬谷 暢崇, 原 隆文
December 2022
Intermediate to advanced
400 pages
4h 27m
Japanese
O'Reilly Japan, Inc.
Content preview from マスタリングLinuxシェルスクリプト 第2版 ―Linuxコマンド、bashスクリプト、シェルプログラミング実践入門

11章正規表現

この章では、ストリームエディター(sed)やAWKを使ううえで最も謎めいた部分について取り上げます。それは正規表現(regular expression:略してregex)です。これまでの章では、いくつかの正規表現について軽く触れる程度でしたが、それは、十分に理解せずに掘り下げることは避けたかったからです。

正規表現の書き方を理解すれば、多くの時間と労力を節約できます。正規表現を使うと、sedやAWKの背後にある真の力を解き放つことができ、それらを専門的に使えるようになります。

この章では、以下のテーマを扱います。

  • 正規表現エンジン
  • BREパターンの定義
  • EREパターンの定義
  • grepの使用

11.1 正規表現エンジン

そもそも、正規表現とは何でしょうか?

正規表現とは、特定のテキストにマッチさせるために正規表現エンジンが解釈する文字列のことです。これは、より進んだ検索方法のようなものです。

たとえば、あるファイルから、任意の小文字で始まる行、数字を含んでいる行、特定のテキストで始まる行を検索したいとします。通常の検索では、そのような総称的な検索はできません。唯一の方法は、正規表現を使うことです。

では、正規表現エンジンとは何でしょうか?

正規表現エンジンは、これらの文字列を理解し、それらを解釈して、マッチするテキストを検索するソフトウェアです。

世の中には多くの正規表現エンジンがあります。たとえば、Java、Perl、Pythonなどのプログラミング言語に標準装備されている正規表現エンジンも、その1つです。また、sedとAWKのようなツールでも正規表現エンジンを使用しており、私たちにとって重要なのは、Linuxでの正規表現エンジンの種類を知ることです。

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版

有賀 康顕, 中山 心太, 西林 孝
バイオインフォマティクスデータスキル ―オープンソースツールを使ったロバストで再現性のある研究

バイオインフォマティクスデータスキル ―オープンソースツールを使ったロバストで再現性のある研究

Vince Buffalo, 片山 俊明, 川島 秀一, 鈴木 治夫, 山本 泰智, 酒匂 寛, 山村 吉信
詳説 イーサネット 第2版

詳説 イーサネット 第2版

Charles E. Spurgeon, Joann Zimmerman, 三浦 史光, 豊沢 聡

Publisher Resources

ISBN: 9784814400119Other