Sorting and columns
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Putting lines in order
sortarranges lines alphabetically (or, with-n, as numbers):
sort names.txt
sort -rreverses the order;sort -nis for lists of numbers.
English
Removing duplicates
uniqremoves neighbouring repeated lines. Because it only looks at neighbours, you usuallysortfirst:
sort names.txt | uniq
- Add
uniq -cto also count how many times each line appeared.

探索
sort, then uniq
uniq only sees neighbours — sort first, so the duplicates sit together.
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:
cut -d : -f 1 people.txt
- That takes the first field of each
name:ageline — the names.
English
Common mistakes
sortis alphabetical;sort -nsorts numbers correctly.cutneeds the right delimiter with-d.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Get a tidy, de-duplicated list of names. Pipe sort 生成 uniq: sort names.txt | uniq.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
people.txt has name:age on each line. Pull out just the names with cut -d : -f 1 people.txt.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
How many times does each name appear in names.txt? Show each name once, with its 计数 in front.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
sizes.txt holds three file sizes. Sort them as numbers, largest first. (Plain sort -r puts 9 first: it compares text.)