Unit 6: Filters and Regular Expressions - Practice Quiz

CSE105 — Creative Engineering Workshop 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What does the grep command primarily do?

grep and Extended grep Easy
A. Searches for lines matching a pattern in files
B. Sorts lines in a file alphabetically
C. Counts the number of words in a file
D. Deletes lines matching a pattern

2 Which option makes grep perform a case-insensitive search?

grep and Extended grep Easy
A. -n
B. -c
C. -i
D. -v

3 Which command is equivalent to grep -E for extended regular expressions?

grep and Extended grep Easy
A. fgrep
B. xgrep
C. ngrep
D. egrep

4 Which grep option displays the line numbers of matching lines?

grep and Extended grep Easy
A. -w
B. -n
C. -l
D. -r

5 Which cut option is used to specify fields to extract?

cut Easy
A. -s
B. -d
C. -c
D. -f

6 In the cut command, what does the -d option specify?

cut Easy
A. The output file
B. The directory path
C. The field delimiter
D. The number of characters

7 By default, how many lines does the head command display?

head Easy
A. 20
B. 10
C. 5
D. 1

8 Which command would you use to view the beginning of a file?

head Easy
A. wc
B. head
C. sort
D. tail

9 Which command displays the last lines of a file?

tail Easy
A. uniq
B. head
C. cut
D. tail

10 Which tail option follows a file and displays new lines as they are added?

tail Easy
A. -r
B. -c
C. -n
D. -f

11 What is the default sorting order of the sort command?

sort Easy
A. Descending alphabetical order
B. By file size
C. Ascending alphabetical order
D. By modification date

12 Which sort option performs a numeric sort instead of alphabetical?

sort Easy
A. -r
B. -f
C. -u
D. -n

13 Which sort option reverses the sorting order?

sort Easy
A. -b
B. -r
C. -k
D. -n

14 What does the wc command count by default?

wc Easy
A. Only lines
B. Lines, words, and bytes
C. Only characters
D. Only words

15 Which wc option displays only the number of lines?

wc Easy
A. -w
B. -l
C. -m
D. -c

16 What is the main purpose of the tr command?

tr Easy
A. Sort lines of text
B. Translate or delete characters
C. Search for patterns
D. Count words in a file

17 Which tr command converts lowercase letters to uppercase?

tr Easy
A. tr -s 'a-z'
B. tr -d 'a-z'
C. tr 'a-z' 'A-Z'
D. tr 'A-Z' 'a-z'

18 What does the uniq command do?

uniq Easy
A. Counts characters in a file
B. Removes adjacent duplicate lines
C. Extracts specific columns
D. Sorts lines alphabetically

19 Which symbol is used to create a pipe between two commands?

Filters with Pipes Easy
A. >
B. |
C. ;
D. &

20 In a regular expression, what does the . (dot) metacharacter match?

Regular Expression Fundamentals Easy
A. A whitespace character
B. Any single character
C. Only a literal period
D. The start of a line

21 Which command lists all lines in data.txt that do not contain the word error?

grep and Extended grep Medium
A. grep -v error data.txt
B. grep -w error data.txt
C. grep -c error data.txt
D. grep -n error data.txt

22 Which egrep (extended grep) command matches lines containing either cat or dog?

grep and Extended grep Medium
A. egrep 'cat+dog' file.txt
B. egrep 'cat&dog' file.txt
C. egrep 'cat\|dog' file.txt
D. egrep 'cat|dog' file.txt

23 What does grep -i 'linux' notes.txt do differently from grep 'linux' notes.txt?

grep and Extended grep Medium
A. Inverts the match for linux
B. Counts occurrences of linux
C. Shows only the first match of linux
D. Matches linux, Linux, LINUX regardless of case

24 Given a file with comma-separated values, which command extracts only the 2nd field?

cut Medium
A. cut -s 2 file.csv
B. cut -d ',' -f 2 file.csv
C. cut -f ',' -d 2 file.csv
D. cut -c 2 file.csv

25 What does cut -c 1-5 file.txt output?

cut Medium
A. The first 5 characters of each line
B. The first 5 fields of each line
C. Characters at positions 1 and 5 only
D. The first 5 lines of the file

26 Which command displays the first 3 lines of log.txt?

head Medium
A. head -l 3 log.txt
B. head -c 3 log.txt
C. head -3 -c log.txt
D. head -n 3 log.txt

27 Which command continuously monitors new lines appended to app.log in real time?

tail Medium
A. tail -n app.log
B. tail -f app.log
C. tail -r app.log
D. tail -c app.log

28 What does tail -n +5 file.txt display?

tail Medium
A. Only line number 5
B. The last 5 lines of the file
C. The first 5 lines of the file
D. All lines starting from line 5 to the end

29 Which command sorts the numbers in nums.txt in numerical order rather than alphabetical order?

sort Medium
A. sort -r nums.txt
B. sort -u nums.txt
C. sort -n nums.txt
D. sort -f nums.txt

30 What does sort -t ':' -k 3 -n /etc/passwd do?

sort Medium
A. Sorts the first 3 fields alphabetically
B. Sorts by the 3rd character of each line
C. Removes the 3rd field before sorting
D. Sorts numerically by the 3rd colon-separated field

31 Which command counts only the number of lines in report.txt?

wc Medium
A. wc -w report.txt
B. wc -m report.txt
C. wc -l report.txt
D. 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)?

wc Medium
A. 12 3 60 file.txt
B. 60 12 3 file.txt
C. 3 60 12 file.txt
D. 3 12 60 file.txt

33 Which command converts all lowercase letters in the input to uppercase?

tr Medium
A. tr -d 'a-z'
B. tr 'a-z' 'A-Z'
C. tr -s 'a-z'
D. tr 'A-Z' 'a-z'

34 What does tr -s ' ' do to its input?

tr Medium
A. Splits the input at each space
B. Squeezes multiple consecutive spaces into a single space
C. Replaces every space with a newline
D. Deletes all spaces from the input

35 Which command removes all digits (0–9) from the input stream?

tr Medium
A. tr -s '0-9'
B. tr -d '0-9'
C. tr -c '0-9'
D. tr '0-9' ' '

36 Why does uniq file.txt sometimes fail to remove all duplicate lines?

uniq Medium
A. uniq only checks the first character
B. uniq only removes duplicates that are adjacent
C. uniq ignores case by default
D. uniq requires the -a option to work

37 Which command shows each unique line along with a count of how many times it occurred?

uniq Medium
A. sort file.txt | uniq -c
B. uniq -u file.txt
C. uniq -d file.txt
D. sort file.txt | uniq -i

38 What does the pipeline cat names.txt | sort | uniq | wc -l compute?

Filters with Pipes Medium
A. The number of duplicated names only
B. The total number of names including duplicates
C. The number of distinct names in the file
D. The number of characters in the file

39 Which pipeline outputs the 3 most frequently occurring words' counts from words.txt?

Filters with Pipes Medium
A. wc -l words.txt | sort | head -n 3
B. sort -rn words.txt | uniq | head -n 3
C. sort words.txt | uniq -c | sort -rn | head -n 3
D. uniq -c words.txt | sort | tail -n 3

40 In a regular expression, what does the pattern ^A match?

Regular Expression Fundamentals Medium
A. A line that ends with the letter A
B. A line without the letter A
C. Any line containing A anywhere
D. A line that begins with the letter 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 and Extended grep Hard
A. grep '^(192|10)\.' data.txt
B. grep -E '^(192|10)\.' data.txt
C. grep -E '(192|10)$' data.txt
D. grep -E '^192|10\.' data.txt

42 What does grep -Ec '^$' file.txt return?

grep and Extended grep Hard
A. An error because ^$ is invalid in ERE
B. The text of all empty lines
C. The count of non-empty lines
D. The count of empty lines in the file

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?

Regular Expression Fundamentals Hard
A. ^[0-9]+(\.[0-9]+)*$
B. ^[0-9]+\.?[0-9]*$
C. ^[0-9]*\.[0-9]+$
D. ^[0-9]+(\.[0-9]+)?$

44 Given a line a:b::c:d, what does echo 'a:b::c:d' | cut -d: -f2,4 output?

cut Hard
A. b:
B. b:d
C. b:c
D. b::c

45 Which command extracts characters 3 through 6 (inclusive) from every line of file.txt?

cut Hard
A. cut -f3-6 file.txt
B. cut -c3-6 file.txt
C. cut -c3,6 file.txt
D. cut -b3:6 file.txt

46 What is the effect of sort -t: -k3,3n -k1,1 /etc/passwd?

sort Hard
A. Sort by the 3rd field only, ignoring ties
B. Sort numerically by the 3rd field, then alphabetically by the 1st field
C. Sort numerically by fields 1 through 3
D. Sort alphabetically by fields 3 and 1 combined

47 For a file where identical lines are scattered (not adjacent), which pipeline correctly counts each distinct line's total occurrences?

uniq Hard
A. uniq -c file
B. sort file | uniq -c
C. sort file | uniq -d
D. uniq -c | sort file

48 What does echo 'HELLO world' | tr -s ' ' | tr 'A-Z' 'a-z' produce?

tr Hard
A. HELLO world
B. helloworld
C. hello world
D. hello world

49 Which command deletes all characters that are NOT digits from the input stream?

tr Hard
A. tr -d '0-9'
B. tr -cd '0-9'
C. tr -s '0-9'
D. tr -c '0-9'

50 What does head -n -5 file.txt output on GNU coreutils?

head Hard
A. The first 5 lines
B. All lines except the last 5
C. The last 5 lines
D. An error for negative count

51 What is the difference between tail -n +10 file.txt and tail -n 10 file.txt?

tail Hard
A. Both print the last 10 lines
B. +10 starts output at line 10; 10 prints the last 10 lines
C. +10 prints line 10 only; 10 prints 10 lines from start
D. +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?

wc Hard
A. 0
B. 1
C. 2
D. 3

53 Which pipeline outputs the 3 most frequently occurring words (space-separated, one per line) in text.txt?

Filters with Pipes Hard
A. cut -d' ' -f1 text.txt | sort -rn | head -3
B. tr ' ' '\n' < text.txt | uniq -c | sort -n | head -3
C. sort text.txt | uniq -c | head -3
D. 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?

grep and Extended grep Hard
A. Prints only the IPv4-like patterns found on each line
B. Validates that octets are between 0 and 255
C. Counts IPv4 addresses per line
D. Prints whole lines containing IPv4 addresses

55 Which statement about the regex a.*b (greedy) matching the string axbxb is correct?

Regular Expression Fundamentals Hard
A. It matches axb (through the first b)
B. It matches xbx
C. It fails to match
D. It matches axbxb (through the last b)

56 Why might sort -n and sort (default) give different results for the lines 10, 2, 1?

sort Hard
A. Default sort treats them as numbers, -n as strings
B. -n compares numeric values; default compares lexically so 10 sorts before 2
C. They always give identical results
D. -n sorts descending while default sorts ascending

57 What does sort file | uniq -u output?

uniq Hard
A. The first occurrence of each line
B. Only lines that appear exactly once
C. All unique lines with counts
D. Only lines that appear more than once

58 Given field1\tfield2\tfield3 (tab-separated), why does cut -d' ' -f2 file.txt fail to extract field2?

cut Hard
A. The default delimiter mismatch: fields are tab-separated, not space
B. cut cannot handle tabs at all
C. -f2 is out of range
D. The -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?

Filters with Pipes Hard
A. The highest exit status among all commands
B. The exit status of cmd1 (the first command)
C. The logical OR of all exit statuses
D. The exit status of 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?

Regular Expression Fundamentals Hard
A. aa* or a\+
B. (a)+
C. a+
D. a{1,} without escaping