0
0
Linux CLIscripting~5 mins

sort and uniq in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the sort command do in Linux?
The sort command arranges lines of text in a file or input alphabetically or numerically. It helps organize data so it's easier to read or process.
Click to reveal answer
beginner
What is the purpose of the uniq command?
uniq filters out repeated lines that are next to each other in a file or input. It shows only one copy of each repeated line.
Click to reveal answer
beginner
Why do you often use sort before uniq?
Because uniq only removes duplicates that are next to each other, sorting first groups duplicates together so uniq can remove all repeated lines.
Click to reveal answer
intermediate
How do you count how many times each line appears using uniq?
Use uniq -c. It adds a number before each line showing how many times that line appeared consecutively.
Click to reveal answer
beginner
What does the command sort file.txt | uniq do?
It sorts the lines in file.txt alphabetically, then removes any duplicate lines, showing only unique lines in order.
Click to reveal answer
What happens if you run uniq file.txt without sorting first?
AOnly consecutive duplicate lines are removed
BAll duplicate lines are removed regardless of position
CThe file is sorted alphabetically
DNothing happens
Which command shows how many times each line appears in a sorted file?
Auniq -c file.txt
Bsort file.txt | uniq -c
Csort -c file.txt
Duniq file.txt
What does sort -r do?
ASorts lines in reverse order
BRemoves duplicates
CCounts lines
DSorts lines randomly
How can you remove duplicate lines ignoring case differences?
Asort | uniq
Bsort -n
Cuniq -c
Dsort -f | uniq -i
What is the output of echo -e "apple\nApple\napple" | sort | uniq?
Aapple
Bapple Apple apple
CApple apple
DApple
Explain how to use sort and uniq together to find unique lines in a file.
Think about why sorting helps uniq work better.
You got /3 concepts.
    Describe how to count the number of times each unique line appears in a text file using Linux commands.
    Counting needs grouping first.
    You got /3 concepts.