メインコンテンツへスキップ
kitlocal.dev

Text CLI (grep / sed / awk) チートシート

ローカルで実行

100% ブラウザ内で処理されます。入力や出力が端末の外に送信されることはありません。

実践的なパイプラインで学ぶ Unix テキスト処理コマンド:GNU grep/ripgrep 検索、sed ストリーム編集、awk フィールド処理・集計、さらに cut、sort、uniq、tr。

動作の仕組み

Unix text tools act like stream filters: each tool reads lines from files or stdin, does one small job (search, slice columns, replace, count, sort) and writes lines to stdout so you can snap them together with `|`.

サバイバルキット

最初に覚えるべき最小限のコマンド。

41 件のコマンド

キーボードショートカット/検索にフォーカスJK選択を移動C選択項目をコピーF選択項目をブックマークEsc検索をクリア

Search lines (grep)

grep prints lines matching a pattern. Add -n for line numbers, -i for case-insensitive and -E for extended regex.

公式ドキュメント: grep usage
  • 基本

    Search recursively and print file paths and line numbers.

    grep -rn "<pattern>" <dir>

    コマンドを組み立てる

    grep -rn "<pattern>" <dir>

    値は入力した通りにそのまま挿入されます。空白や特殊文字を含む場合は、必要に応じて引用符で囲んでください。

    使いどころ

    Find every occurrence of a function, error code or config key across a directory tree.

    コマンドの内訳

    -r
    recurse into subdirectories
    -n
    prefix matches with 1-based line numbers
    <pattern>
    search regex or text
    <dir>
    directory to search (use `.` for current)

    実例

    printf "200 GET /api\n500 POST /pay\n200 GET /api\n404 GET /old\n" | grep -n "GET"

    実行結果

    1:200 GET /api
    3:200 GET /api
    4:404 GET /old

    他の方法

    • rg "<pattern>" (ripgrep, skips .gitignore automatically)

    関連項目

Transform text streams (sed)

sed edits lines on the fly. Test without `-i` first so you preview changes on stdout before modifying files.

公式ドキュメント: sed commands

Process columns & aggregate (awk)

awk splits every line into fields ($1, $2, ...) automatically, running `{ action }` whenever `condition` is true.

公式ドキュメント: GNU Awk User Guide

Sort, count, cut & translate

Fast single-purpose coreutils for frequency counts, column slicing and character cleanup.

公式ドキュメント: Operating on sorted files

Find files & batch commands (find, xargs)

Locate files by name, size or age and pass them safely to downstream commands using NUL delimiters.

公式ドキュメント: GNU Findutils Manual

KitLocalツールで試す

用語集
stdin / stdout
Standard input and output streams wired together by pipes (`|`).
ERE (-E)
Extended Regular Expressions: `+`, `?`, `|`, `()` work without extra backslashes.
Field ($1, $NF)
In awk, columns split by whitespace (or `-F`): `$0` is the whole line, `$NF` is the last column.
NUL delimiter (-0)
Separating paths with `\0` instead of newlines so spaces and quotes never break pipelines.

2026/11/15 に検証済み · GNU grep 3.12 / sed 4.9 / gawk 5.3 で検証済み

出典: GNU Coreutils Manual · GNU grep Manual · GNU sed Manual · GNU Awk Manual

山括弧内の内容は実際の値に置き換えてください。コマンドは公式ドキュメントに基づいており、実例は記載されたバージョンで実行確認されています。