Chuyển tới nội dung chính
kitlocal.dev

Bảng tra cứu Text CLI (grep / sed / awk)

Chạy cục bộ

Xử lý 100% ngay trong trình duyệt. Dữ liệu đầu vào và kết quả không rời khỏi thiết bị.

Bộ lệnh xử lý văn bản Unix qua pipeline: tìm kiếm với GNU grep/ripgrep, biến đổi luồng sed, lọc cột bằng awk cùng cut, sort, uniq và tr.

Cách hoạt động

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 `|`.

Bộ lệnh sống còn

Vài lệnh nên học trước tiên.

41 lệnh

Phím tắt/Tìm kiếmJKDi chuyển mục chọnCSao chép lệnh đang chọnFĐánh dấu mục đang chọnEscXoá tìm kiếm

Search lines (grep)

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

Tài liệu chính thức: grep usage
  • Cơ bản

    Search recursively and print file paths and line numbers.

    grep -rn "<pattern>" <dir>

    Dựng lệnh

    grep -rn "<pattern>" <dir>

    Giá trị được chèn đúng như bạn nhập. Hãy tự đặt dấu nháy nếu giá trị có khoảng trắng hoặc ký tự đặc biệt.

    Khi nào dùng

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

    Giải thích từng phần

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

    Ví dụ

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

    Kết quả

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

    Cách khác

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

    Xem thêm

Transform text streams (sed)

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

Tài liệu chính thức: sed commands

Process columns & aggregate (awk)

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

Tài liệu chính thức: GNU Awk User Guide

Sort, count, cut & translate

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

Tài liệu chính thức: 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.

Tài liệu chính thức: GNU Findutils Manual

Dùng thử trong công cụ KitLocal

Thuật ngữ
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.

Kiểm tra ngày 15 thg 11, 2026 · Đối chiếu với GNU grep 3.12 / sed 4.9 / gawk 5.3

Nguồn: GNU Coreutils Manual · GNU grep Manual · GNU sed Manual · GNU Awk Manual

Hãy thay phần trong dấu ngoặc nhọn bằng giá trị của bạn. Lệnh lấy từ tài liệu chính thức, ví dụ đã được chạy thử trên phiên bản được ghi.