Linux Command Line Mastery · درس

دمج المخرجات وفرزها باستخدام sort وuniq وcut

تعلّم إعادة تشكيل النص المتدفق وتلخيصه عبر فرز الأسطر وإزالة التكرارات واستخراج الحقول باستخدام sort وuniq وcut.

الدرس 4 من 413 خطوة

دمج المخرجات وفرزها باستخدام sort وuniq وcut درس مجاني في Linux Command Line Mastery على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Command Line Mastery، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why sort, uniq, and cut Matter

Filtering with grep and editing with sed/awk gets you far, but real pipelines often need to reorder, deduplicate, and slice columns of text.

  • sort orders lines
  • uniq collapses duplicates
  • cut extracts fields

Together they turn raw streams into clean summaries.

Basic Sorting

sort reads lines and prints them in lexical order by default. It works great inside a pipe.

printf 'banana\napple\ncherry\n' | sort

Numeric and Reverse Sort

Use -n for numeric order and -r to reverse. Without -n, 10 sorts before 2.

printf '10\n2\n33\n4\n' | sort -n -r

Sorting by a Specific Field

-k picks the column to sort on and -t sets the delimiter. Here we sort a CSV by the second field numerically.

printf 'alice,30\nbob,25\ncarol,40\n' | sort -t, -k2 -n

Removing Duplicates with uniq

uniq only collapses adjacent duplicate lines, so you almost always sort first.

printf 'a\na\nb\na\n' | sort | uniq

Counting Occurrences

uniq -c prefixes each line with how many times it appeared. This is the classic frequency-count idiom.

printf 'err\nok\nerr\nerr\nok\n' | sort | uniq -c

Top-N Frequency Report

Combine the tools to build a leaderboard: count, then sort the counts descending.

printf 'GET\nPOST\nGET\nGET\nPOST\n' | sort | uniq -c | sort -nr

Extracting Columns with cut

cut -d sets the delimiter and -f selects fields. Here we grab the username column from a colon-separated record.

printf 'root:x:0\nalice:x:1000\n' | cut -d: -f1

Cutting by Character Position

cut -c selects character ranges instead of fields, useful for fixed-width data.

printf 'ABCDEF\nGHIJKL\n' | cut -c2-4

Finding Only Unique or Only Duplicated Lines

uniq -u prints lines that appear exactly once; uniq -d prints only those that repeat.

printf 'x\ny\nx\nz\n' | sort | uniq -d

A Full Pipeline

Put it all together: extract a field, sort it, count duplicates, and rank. This pattern answers questions like which IP hit us most?

printf '1.1.1.1 GET\n2.2.2.2 GET\n1.1.1.1 POST\n' | cut -d' ' -f1 | sort | uniq -c | sort -nr

Quick Check

Why must you usually run sort before uniq?

Recap

You can now reshape text streams end to end:

  • sort (with -n, -r, -k, -t) orders lines
  • uniq (with -c, -d, -u) deduplicates and counts
  • cut (with -d/-f or -c) extracts fields

The cut | sort | uniq -c | sort -nr chain is one of the most useful one-liners in Linux.

البدء مجانًا

تعلم Linux Command Line Mastery مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «دمج المخرجات وفرزها باستخدام sort وuniq وcut» مجاني؟

نعم — نص درس «دمج المخرجات وفرزها باستخدام sort وuniq وcut» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Command Line Mastery، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

ماذا ستتعلم في «دمج المخرجات وفرزها باستخدام sort وuniq وcut»؟

تعلّم إعادة تشكيل النص المتدفق وتلخيصه عبر فرز الأسطر وإزالة التكرارات واستخراج الحقول باستخدام sort وuniq وcut. تتمرن على Linux Command Line Mastery مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Linux Command Line Mastery؟

لا تُشترط خبرة سابقة. Linux Command Line Mastery على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «دمج المخرجات وفرزها باستخدام sort وuniq وcut»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Linux Command Line Mastery هذا؟

نعم. كل درس في Linux Command Line Mastery يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. التدفقات القياسية وإعادة التوجيه
  2. تصفية النص باستخدام `grep`
  3. معالجة النصوص باستخدام `sed` و`awk`
  4. دمج المخرجات وفرزها باستخدام sort وuniq وcut
← العودة إلى Linux Command Line Mastery