Unit 6: Filters and Regular Expressions - Practice Quiz
1
What does the grep command primarily do?
2
Which option makes grep perform a case-insensitive search?
-n
-c
-i
-v
3
Which command is equivalent to grep -E for extended regular expressions?
fgrep
xgrep
ngrep
egrep
4
Which grep option displays the line numbers of matching lines?
-w
-n
-l
-r
5
Which cut option is used to specify fields to extract?
-s
-d
-c
-f
6
In the cut command, what does the -d option specify?
7
By default, how many lines does the head command display?
8 Which command would you use to view the beginning of a file?
wc
head
sort
tail
9 Which command displays the last lines of a file?
uniq
head
cut
tail
10
Which tail option follows a file and displays new lines as they are added?
-r
-c
-n
-f
11
What is the default sorting order of the sort command?
12
Which sort option performs a numeric sort instead of alphabetical?
-r
-f
-u
-n
13
Which sort option reverses the sorting order?
-b
-r
-k
-n
14
What does the wc command count by default?
15
Which wc option displays only the number of lines?
-w
-l
-m
-c
16
What is the main purpose of the tr command?
17
Which tr command converts lowercase letters to uppercase?
tr -s 'a-z'
tr -d 'a-z'
tr 'a-z' 'A-Z'
tr 'A-Z' 'a-z'
18
What does the uniq command do?
19 Which symbol is used to create a pipe between two commands?
>
|
;
&
20
In a regular expression, what does the . (dot) metacharacter match?
21
Which command lists all lines in data.txt that do not contain the word error?
grep -v error data.txt
grep -w error data.txt
grep -c error data.txt
grep -n error data.txt
22
Which egrep (extended grep) command matches lines containing either cat or dog?
egrep 'cat+dog' file.txt
egrep 'cat&dog' file.txt
egrep 'cat\|dog' file.txt
egrep 'cat|dog' file.txt
23
What does grep -i 'linux' notes.txt do differently from grep 'linux' notes.txt?
linux
linux
linux
linux, Linux, LINUX regardless of case
24 Given a file with comma-separated values, which command extracts only the 2nd field?
cut -s 2 file.csv
cut -d ',' -f 2 file.csv
cut -f ',' -d 2 file.csv
cut -c 2 file.csv
25
What does cut -c 1-5 file.txt output?
26
Which command displays the first 3 lines of log.txt?
head -l 3 log.txt
head -c 3 log.txt
head -3 -c log.txt
head -n 3 log.txt
27
Which command continuously monitors new lines appended to app.log in real time?
tail -n app.log
tail -f app.log
tail -r app.log
tail -c app.log
28
What does tail -n +5 file.txt display?
29
Which command sorts the numbers in nums.txt in numerical order rather than alphabetical order?
sort -r nums.txt
sort -u nums.txt
sort -n nums.txt
sort -f nums.txt
30
What does sort -t ':' -k 3 -n /etc/passwd do?
31
Which command counts only the number of lines in report.txt?
wc -w report.txt
wc -m report.txt
wc -l report.txt
wc -c report.txt
32
A file contains 3 lines with a total of 12 words and 60 characters. What does wc file.txt print (in order)?
12 3 60 file.txt
60 12 3 file.txt
3 60 12 file.txt
3 12 60 file.txt
33 Which command converts all lowercase letters in the input to uppercase?
tr -d 'a-z'
tr 'a-z' 'A-Z'
tr -s 'a-z'
tr 'A-Z' 'a-z'
34
What does tr -s ' ' do to its input?
35 Which command removes all digits (0–9) from the input stream?
tr -s '0-9'
tr -d '0-9'
tr -c '0-9'
tr '0-9' ' '
36
Why does uniq file.txt sometimes fail to remove all duplicate lines?
uniq only checks the first character
uniq only removes duplicates that are adjacent
uniq ignores case by default
uniq requires the -a option to work
37 Which command shows each unique line along with a count of how many times it occurred?
sort file.txt | uniq -c
uniq -u file.txt
uniq -d file.txt
sort file.txt | uniq -i
38
What does the pipeline cat names.txt | sort | uniq | wc -l compute?
39
Which pipeline outputs the 3 most frequently occurring words' counts from words.txt?
wc -l words.txt | sort | head -n 3
sort -rn words.txt | uniq | head -n 3
sort words.txt | uniq -c | sort -rn | head -n 3
uniq -c words.txt | sort | tail -n 3
40
In a regular expression, what does the pattern ^A match?
A
A
A anywhere
A
41
Consider the file data.txt. Which command prints only lines containing a valid IPv4 octet range check for the first octet being 192 or 10, using extended regex anchored at line start?
grep '^(192|10)\.' data.txt
grep -E '^(192|10)\.' data.txt
grep -E '(192|10)$' data.txt
grep -E '^192|10\.' data.txt
42
What does grep -Ec '^$' file.txt return?
^$ is invalid in ERE
43
In a POSIX ERE, which pattern matches a string that is a sequence of one or more digits optionally followed by exactly one decimal part like .25?
^[0-9]+(\.[0-9]+)*$
^[0-9]+\.?[0-9]*$
^[0-9]*\.[0-9]+$
^[0-9]+(\.[0-9]+)?$
44
Given a line a:b::c:d, what does echo 'a:b::c:d' | cut -d: -f2,4 output?
b:
b:d
b:c
b::c
45
Which command extracts characters 3 through 6 (inclusive) from every line of file.txt?
cut -f3-6 file.txt
cut -c3-6 file.txt
cut -c3,6 file.txt
cut -b3:6 file.txt
46
What is the effect of sort -t: -k3,3n -k1,1 /etc/passwd?
47 For a file where identical lines are scattered (not adjacent), which pipeline correctly counts each distinct line's total occurrences?
uniq -c file
sort file | uniq -c
sort file | uniq -d
uniq -c | sort file
48
What does echo 'HELLO world' | tr -s ' ' | tr 'A-Z' 'a-z' produce?
HELLO world
helloworld
hello world
hello world
49 Which command deletes all characters that are NOT digits from the input stream?
tr -d '0-9'
tr -cd '0-9'
tr -s '0-9'
tr -c '0-9'
50
What does head -n -5 file.txt output on GNU coreutils?
51
What is the difference between tail -n +10 file.txt and tail -n 10 file.txt?
+10 starts output at line 10; 10 prints the last 10 lines
+10 prints line 10 only; 10 prints 10 lines from start
+10 prints the first 10 lines; 10 prints the last 10
52
For a file ending without a trailing newline containing a\nb\nc (no newline after c), what does wc -l report?
0
1
2
3
53
Which pipeline outputs the 3 most frequently occurring words (space-separated, one per line) in text.txt?
cut -d' ' -f1 text.txt | sort -rn | head -3
tr ' ' '\n' < text.txt | uniq -c | sort -n | head -3
sort text.txt | uniq -c | head -3
tr ' ' '\n' < text.txt | sort | uniq -c | sort -rn | head -3
54
What does grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' log.txt do?
55
Which statement about the regex a.*b (greedy) matching the string axbxb is correct?
axb (through the first b)
xbx
axbxb (through the last b)
56
Why might sort -n and sort (default) give different results for the lines 10, 2, 1?
-n as strings
-n compares numeric values; default compares lexically so 10 sorts before 2
-n sorts descending while default sorts ascending
57
What does sort file | uniq -u output?
58
Given field1\tfield2\tfield3 (tab-separated), why does cut -d' ' -f2 file.txt fail to extract field2?
cut cannot handle tabs at all
-f2 is out of range
-d' ' syntax is invalid
59
A pipeline cmd1 | cmd2 | cmd3 returns a nonzero status. In a default bash shell (no pipefail), which command's exit status is used?
cmd1 (the first command)
cmd3 (the last command)
60
In BRE (basic regular expressions used by default grep), which is the correct way to match one or more a characters?
aa* or a\+
(a)+
a+
a{1,} without escaping
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →