find ./ -type f | xargs grep "s-s-2"
出典(authority):フリー百科事典『ウィキペディア(Wikipedia)』「2019/06/12 14:06:58」(JST)
この項目では、UNIXの検索コマンドについて説明しています。同人ショップについては「グレップ」をご覧ください。 |
grep
(グレップ、グレプ)は、UNIXおよびUnixオペレーティングシステムにおけるコマンド。テキストファイル中から、正規表現に一致する行を検索して出力する。
grep
の名の由来は、ラインエディタedのコマンド g/re/p
である。その意味するところは「global regular expression print(ファイル全体から/正規表現に一致する行を/表示する)」で略号になっている。[1]。
姉妹コマンドとして、正規表現ではなくリテラル(即値文字列)のみを扱う高速な fgrep
[2]、拡張正規表現が使える egrep
[3] がある。POSIX では fgrep
、egrep
を旧形式としていて、それぞれ grep -F
、grep -E
を使うことを標準としている。Linux Standard Baseでも指定コマンドになっている[4]。
grep
コマンドの基本的な使い方は
grep
オプション パターン ファイル
である。
ファイルは複数指定することができ、また省略して標準入力から検索することもできる。
オプションには次のようなものがある:
-i
: アルファベットの大文字小文字の区別をしない。-o
:パターンに一致した箇所のみ出力する。-v
: パターンに一致しない行を出力する。-r
: ファイルとしてディレクトリを指定し、その中の全てのファイルと、再帰的に下位ディレクトリに対して検索する。-q
:何も出力しない。-E
: 拡張正規表現を使用する。egrep
コマンドと同じ動作をする。-F
: 正規表現ではなくリテラルを使用する。fgrep
コマンドと同じ動作をする。テキストから文字列を検索するプログラムとして、有志により、MS-DOS や Microsoft Windows 用に多数移植されている。また、テキストから文字列を検索するプログラムのことを grep と呼ばれることもある。
[ヘルプ] |
find
agrep
grep
(1) - Linux JMプロジェクトによる日本語のマニュアルページgrep
(1) - man page(SunOS リファレンス・マニュアル)grep
(1) (PDF) - man page(HP-UX リファレンス)この項目は、ソフトウェアに関連した書きかけの項目です。この項目を加筆・訂正などしてくださる協力者を求めています(PJ:コンピュータ/P:コンピュータ)。 |
|
Example of grep command | |
Original author(s) | Ken Thompson[1][2] |
---|---|
Developer(s) | AT&T Bell Laboratories |
Initial release | November 1974; 44 years ago (1974-11)[1] |
Stable release | 3.3[3]
/ 20 December 2018; 5 months ago (2018-12-20) |
Platform | Unix and Unix-like, OS-9 |
Type | Command |
License | GNU General Public License |
Website | www |
grep
is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression and print), which has the same effect: doing a global search with the regular expression and printing all matching lines.[4][5] Grep was originally developed for the Unix operating system, but later available for all Unix-like systems and some others such as OS-9.[6]
Before it was named grep, it was a private utility to search files written by Ken Thompson. He was approached by his manager, Doug McIlroy, who said it would be great if we could look for things in files. Thompson said he would think about it overnight, but the "overnight think" was actually fixing bugs and doing things he had meant to do with it, about an hour's work. The next day Thompson presented McIlroy with grep, who said it was exactly what he wanted. Thompson's account may explain why it is believed that grep was written overnight.[7]
The first version of grep was written overnight by Ken Thompson in PDP-11 assembly language to help Lee E. McMahon analyze the text of the Federalist Papers to determine authorship of the individual papers.[8] The ed text editor (also authored by Thompson) had regular expression support but could not be used on such a large amount of text, so Thompson excerpted that code into a standalone tool.[1] Thompson chose the name because in ed, the command g/re/p would print all lines matching a previously defined pattern.[9][10] grep was first included in Version 4 Unix. Stating that it is "generally cited as the prototypical software tool", Doug McIlroy credited grep with "irrevocably ingraining" Thompson's tools philosophy in Unix.[11]
The following example demonstrates the output of the grep
command given different arguments
$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
$ grep -n root /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
12:operator:x:11:0:operator:/root:/sbin/nologin
$ grep -c false /etc/passwd
7
A variety of grep implementations are available in many operating systems and software development environments.[12] Early variants included egrep
and fgrep
, introduced in Version 7 Unix.[11] The "egrep
" variant supports an extended regular expression syntax added by Alfred Aho after Ken Thompson's original regular expression implementation.[13] The "fgrep
" variant searches for any of a list of fixed strings using the Aho–Corasick string matching algorithm.[14] Binaries of these variants persist in most modern systems, however their explicit usage has been deprecated and the functionalities of these variants are included in grep
as the command-line switches -E
and -F
; the use of the switches is therefore the recommended method of use.[15]
Other commands contain the word "grep" to indicate that they search (usually for regular expression matches). The pgrep utility, for instance, displays the processes whose names match a given regular expression.[16]
In the Perl programming language, grep is the name of the built-in function that finds elements in a list that satisfy a certain property.[17] This higher-order function is typically named filter in functional programming languages.
The pcregrep
command is an implementation of grep that uses Perl regular expression syntax.[18] Similar functionality can be invoked in the GNU version of grep with the -P
flag.[19]
Ports of grep
(within Cygwin and GnuWin32, for example) also run under Microsoft Windows. Some versions of Windows feature the similar qgrep
or findstr
command.[20]
The software Adobe InDesign has functions GREP (since CS3 version (2007)[21]), in the find/change dialog box[22] "GREP" tab, and introduced with InDesign CS4[23] in paragraph styles[24] "GREP styles".
In December 2003, the Oxford English Dictionary Online added draft entries for "grep" as both a noun and a verb.
A common verb usage is the phrase "You can't grep dead trees"—meaning one can more easily search through digital media, using tools such as grep, than one could with a hard copy (i.e., one made from dead trees, paper).[25] Compare with google.
grep
grep
QGREP.EXE[:] A similar tool to grep in UNIX, this tool can be used to search for a text string
The Wikibook How To Search has a page on the topic of: grep |
Unix command-line interface programs and shell builtins | |
---|---|
File system |
|
Processes |
|
User environment |
|
Text processing |
|
Shell builtins |
|
Searching |
|
Documentation |
|
Software development |
|
Miscellaneous |
|
|
Authority control |
|
---|
リンク元 | 「find」 |
拡張検索 | 「grepafloxacin hydrochloride hydrate」「grepafloxacin hydrochloride」「grepafloxacin」 |
find / -name "a*.*"
.