Sorting and columns · Sắp xếp và cột
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
Putting lines in order
sortarranges lines alphabetically (or, with-n, as numbers):
sort -rreverses the order;sort -nis for lists of numbers.
Tiếng Việt
Sắp xếp các dòng
sortsắp xếp các dòng theo bảng chữ cái (hoặc, với-n, theo thứ tự số):
sort names.txt
sort -rđảo ngược thứ tự;sort -ndành cho danh sách các con số.
English
Removing duplicates
uniqremoves neighbouring repeated lines. Because it only looks at neighbours, you usuallysortfirst:
- Add
uniq -cto also count how many times each line appeared.
Tiếng Việt
Loại bỏ trùng lặp
uniqloại bỏ các dòng trùng lặp liền kề. Vì nó chỉ xem xét các邻居 (ngân hàng), bạn thường cầnsorttrước:
sort names.txt | uniq
- Thêm
uniq -cđể đếm xem mỗi dòng xuất hiện bao nhiêu lần.
Explore · Khám phá
sort, then uniq · sort, sau đó uniq
uniq only sees neighbours — sort first, so the duplicates sit together. · uniq chỉ thấy các hàng lân cận — sort trước, nên các bản sao nằm cạnh nhau.
English
Picking out columns
- Many files have columns separated by a character — a comma, a colon, a tab.
cutpulls out the columns you want.-dsets the delimiter,-fthe field:
- That takes the first field of each
name:ageline — the names.
Tiếng Việt
Trích xuất cột
- Nhiều tập tin có các cột được ngăn cách bởi một ký tự — dấu phẩy, dấu hai chấm, hoặc tab.
cuttrích xuất các cột bạn muốn.-dthiết lập delimiter (kí tự phân cách),-fchỉ định field (cột):
cut -d : -f 1 people.txt
- Lệnh này lấy trường đầu tiên của mỗi dòng
name:age— đó là các tên.
English
Common mistakes
sortis alphabetical;sort -nsorts numbers correctly.cutneeds the right delimiter with-d.
Tiếng Việt
Lỗi thường gặp
sortsắp xếp theo bảng chữ cái;sort -nsắp xếp các số đúng cách.cutcần delimiter phù hợp với-d.
Get a tidy, de-duplicated list of names. Pipe sort into uniq: sort names.txt | uniq. · Lấy một danh sách tên gọn gàng, đã loại bỏ trùng lặp. Pipe sort vào uniq: sort names.txt | uniq.
people.txt has name:age on each line. Pull out just the names with cut -d : -f 1 people.txt. · people.txt có name:age trên mỗi dòng. Trích xuất chỉ tên với cut -d : -f 1 people.txt.