Searching with grep · grep で検索する
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Finding text with grep
grepsearches for a word and prints only the lines that contain it:
- Out of a huge log, you instantly see just the lines that matter.
日本語
grep でテキストを探す
grepは単語を検索し、含まれる行のみを表示します:
grep error log.txt
- 膨大なログの中から、必要な行だけを即座に見ることができます。
English
Useful options
-iignores case (soErrormatcheserror).-nshows the line number of each match.-vinverts — show lines that do not match.
日本語
便利なオプション
-iは大文字小文字を区別しないため、Errorはerrorにも一致します。-nは各一致の行番号を表示します。-vは逆指定 — 一致しない行を表示します。
grep -n ok log.txt
English
grep loves pipes
grepshines at the end of a pipe, filtering another command's output:
- "How many error lines?" — filter to errors, then count them. A everyday combo.
日本語
grep はパイプを好む
grepはパイプの最後に使われると、他のコマンドの出力をフィルタリングする際に光ります:
cat log.txt | grep error | wc -l
- 「エラー行はいくつあるか?」 — エラーにフィルタリングして数え上げます。日常使いのコモネーションです。
English
Common mistakes
grep pattern filefinds matching lines; add-ito ignore case.- Quote a pattern that has spaces or special characters.
日本語
よくあるミス
grep pattern fileは一致する行を探し、-iを加えると大文字小文字を無視します。- スペースや特殊文字を含むパターンは引用符で囲みます。
Explore · 探索
grep inside a pipeline · パイプライン内の grep
grep filters a stream — feed it the output of another command. · grep はストリームをフィルタリングする — 他のコマンドの出力を渡す。
Show only the lines of log.txt that contain error, using grep error log.txt. · log.txt の error を含む行のみを grep error log.txt で表示する。
How many errors are there? Pipe grep into wc -l: grep error log.txt | wc -l. · エラーはいくつありますか? grep をwc -l にパイプします:grep error log.txt | wc -l 。