Sorting and columns · ソートと列
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Putting lines in order
sortarranges lines alphabetically (or, with-n, as numbers):
sort -rreverses the order;sort -nis for lists of numbers.
日本語
行を並べる
sortは行をアルファベット順に並べ替えます(-nを使うと数字として):
sort names.txt
sort -rは順序を逆転させ、sort -nは数字のリストに適しています。
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.
日本語
重複を削除する
uniqは隣り合う重複した行を削除します。隣同士しか見ないため、通常はsortを先に行います:
sort names.txt | uniq
uniq -cを加えると、各行が何回出現したかも数え上げて表示します。
Explore · 探索
sort, then uniq · sort、そして uniq
uniq only sees neighbours — sort first, so the duplicates sit together. · uniq は隣同士しか見ない — sort で先にソートすることで重複が一緒に集まる。
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.
日本語
カラムを抽出する
- 多くのファイルは、コンマ、コロン、タブなどの文字でカラムが区切られています。
cutは目的のカラムを抽出します。-dはdelimiter(区切り文字)を、-fはfield(フィールド)を設定します:
cut -d : -f 1 people.txt
- これは
name:ageの各行の最初のフィールド — 名前 — を取り出します。
English
Common mistakes
sortis alphabetical;sort -nsorts numbers correctly.cutneeds the right delimiter with-d.
日本語
よくあるミス
sortはアルファベット順、sort -nは数字を正しくソートします。cutには-dとセットの正しい区切り文字が必要です。
Get a tidy, de-duplicated list of names. Pipe sort into uniq: sort names.txt | uniq. · 整然とした重複除去済みの名前リストを得る。sort を 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 は各行に name:age がある。名前だけを cut -d : -f 1 people.txt で抽出する。