Ausgaben mit sort, uniq und cut kombinieren und sortieren
Lernen Sie, gestreamten Text umzuformen und zusammenzufassen, indem Sie Zeilen sortieren, Duplikate entfernen und Felder mit sort, uniq und cut extrahieren.
Ausgaben mit sort, uniq und cut kombinieren und sortieren ist eine kostenlose Linux Command Line Mastery-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Linux Command Line Mastery-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
sortorders linesuniqcollapses duplicatescutextracts 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' | sortNumeric 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 -rSorting 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 -nRemoving Duplicates with uniq
uniq only collapses adjacent duplicate lines, so you almost always sort first.
printf 'a\na\nb\na\n' | sort | uniqCounting 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 -cTop-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 -nrExtracting 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: -f1Cutting by Character Position
cut -c selects character ranges instead of fields, useful for fixed-width data.
printf 'ABCDEF\nGHIJKL\n' | cut -c2-4Finding 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 -dA 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 -nrQuick 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 linesuniq(with-c,-d,-u) deduplicates and countscut(with-d/-for-c) extracts fields
The cut | sort | uniq -c | sort -nr chain is one of the most useful one-liners in Linux.
Häufig gestellte Fragen
Ist die Lektion „Ausgaben mit sort, uniq und cut kombinieren und sortieren“ kostenlos?
Ja — der vollständige Text von „Ausgaben mit sort, uniq und cut kombinieren und sortieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Linux Command Line Mastery-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Ausgaben mit sort, uniq und cut kombinieren und sortieren“?
Lernen Sie, gestreamten Text umzuformen und zusammenzufassen, indem Sie Zeilen sortieren, Duplikate entfernen und Felder mit sort, uniq und cut extrahieren. Du übst Linux Command Line Mastery mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Linux Command Line Mastery zu starten?
Keine Vorkenntnisse erforderlich. Linux Command Line Mastery auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Ausgaben mit sort, uniq und cut kombinieren und sortieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Linux Command Line Mastery-Lektion Code schreiben und ausführen?
Ja. Jede Linux Command Line Mastery-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Standarddatenströme und Umleitung
- Text mit `grep` filtern
- Textverarbeitung mit `sed` und `awk`
- Ausgaben mit sort, uniq und cut kombinieren und sortieren