Searching with grep · Tìm kiếm với grep
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
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.
Tiếng Việt
Tìm kiếm văn bản với grep
greptìm kiếm một từ và chỉ in ra các dòng chứa từ đó:
grep error log.txt
- Từ một nhật ký khổng lồ, bạn ngay lập tức chỉ thấy những dòng quan trọng.
English
Useful options
-iignores case (soErrormatcheserror).-nshows the line number of each match.-vinverts — show lines that do not match.
Tiếng Việt
Các tùy chọn hữu ích
-ibỏ qua viết hoa/thường (nênErrorsẽ khớp vớierror).-nhiển thị số dòng của mỗi kết quả khớp.-vlật ngược — hiển thị các dòng không khớp.
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.
Tiếng Việt
grep yêu thích đường ống
grepphát huy tối đa ở cuối đường ống, lọc kết quả của một lệnh khác:
cat log.txt | grep error | wc -l
- "Có bao nhiêu dòng lỗi?" — lọc ra các dòng lỗi, sau đó đếm chúng. Đây là sự kết hợp quen thuộc hàng ngày.
English
Common mistakes
grep pattern filefinds matching lines; add-ito ignore case.- Quote a pattern that has spaces or special characters.
Tiếng Việt
Lỗi thường gặp
grep pattern filetìm các dòng khớp; hãy thêm-iđể bỏ qua viết hoa/thường.- Đặt mẫu (pattern) trong dấu ngoặc kép nếu nó có khoảng trắng hoặc ký tự đặc biệt.
Explore · Khám phá
grep inside a pipeline · grep trong pipeline
grep filters a stream — feed it the output of another command. · grep lọc một luồng — cấp cho nó đầu ra của một lệnh khác.
Show only the lines of log.txt that contain error, using grep error log.txt. · Chỉ hiển thị các dòng của log.txt chứa error, dùng grep error log.txt.
How many errors are there? Pipe grep into wc -l: grep error log.txt | wc -l. · Có bao nhiêu lỗi? Pipe grep vào wc -l: grep error log.txt | wc -l.