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.
ไทย
เลือกคอลัมน์
- ไฟล์หลายไฟล์มีคอลัมน์ที่แยกด้วยตัวอักษร —逗号, คอลอน, Tab
cutดึงคอลัมน์ที่คุณต้องการ出来-dตั้งค่า delimiter,-ffield:
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ต้องใช้ delimiter ที่ถูกต้องกับ-d
Get a tidy, de-duplicated list of names. Pipe sort into uniq: sort names.txt | uniq. · รับรายการชื่อที่เรียบร้อย, ไม่ซ้ำกัน Pipe 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