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?✗ Incorrect
uniq only removes duplicates that are next to each other. Without sorting, duplicates separated by other lines stay.
Which command shows how many times each line appears in a sorted file?
✗ Incorrect
Sorting first groups duplicates, then uniq -c counts each group.
What does
sort -r do?✗ Incorrect
-r option sorts lines in reverse (descending) order.
How can you remove duplicate lines ignoring case differences?
✗ Incorrect
sort -f ignores case, and uniq -i ignores case when filtering duplicates.
What is the output of
echo -e "apple\nApple\napple" | sort | uniq?✗ Incorrect
Sorting puts 'Apple' before 'apple'. uniq sees them as different because of case, so both appear.
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.