Unit 6: Filters and Regular Expressions - Subjective Questions

CSE105 — Creative Engineering Workshop • Practice Questions with Detailed Answers

20 questions

1

Define a filter in the context of Unix/Linux commands. Explain how filters process data and give three examples of commonly used filters.

2

Explain the grep command with its syntax. Describe at least five important options of grep with examples.

3

Distinguish between grep, egrep, and fgrep. When would you use Extended grep?

4

Explain the cut command in detail. How can it be used to extract columns and character ranges from a file?

5

Describe the head and tail commands. How can tail be used to monitor a growing log file in real time?

6

Explain the sort command with its important options. Illustrate numeric, reverse, and field-based sorting with examples.

7

Explain the wc command. How does it count lines, words, and characters? Provide examples of its usage in pipelines.

8

Explain the tr command. Describe how it is used for translating, deleting, and squeezing characters with suitable examples.

9

Explain the uniq command. Why is sort usually used before uniq? Describe its important options with examples.

10

What is a pipe in Unix/Linux? Explain how filters can be combined using pipes to build powerful command pipelines with examples.

11

Define a Regular Expression (regex). Explain the fundamental building blocks of regular expressions with examples.

12

Explain the different anchors and quantifiers used in regular expressions with suitable examples.

13

Compare Basic Regular Expressions (BRE) and Extended Regular Expressions (ERE). List the metacharacters that differ between them.

14

Explain character classes in regular expressions. Describe POSIX character classes with examples.

15

With the help of examples, explain how grep is used with regular expressions to solve real-world text searching problems.

16

Write and explain shell command pipelines to perform the following tasks: (a) Display the top 3 users consuming the most disk space, (b) Count the number of unique words in a file, (c) List the 5 most frequently occurring lines in a log file.

17

Explain the concept of standard input, standard output, and standard error streams. How do filters and pipes make use of these streams?

18

Describe how the sort, uniq, and wc commands can be combined to generate a word frequency report from a text file. Explain each stage of the pipeline.

19

Explain the role of escaping and the backslash (\) in regular expressions. Why is escaping important, and what happens when metacharacters are used as literals?

20

A file students.txt contains records in the format RollNo:Name:Marks:Branch. Write and explain commands to: (a) Extract only names, (b) Display records sorted by marks in descending order, (c) Count students in the CSE branch.