Unix text-processing tools: Which of the following is <em>not</em> a filter command (i.e., a program that reads from standard input and writes to standard output)?

Difficulty: Easy

Correct Answer: None of the above

Explanation:


Introduction / Context:
Unix excels at building pipelines by connecting programs that read from standard input and write to standard output—these are commonly called filters. Recognizing which commands behave as filters helps you compose effective pipelines for searching, counting, sorting, and transforming text.



Given Data / Assumptions:

  • A filter typically reads from stdin and writes to stdout.
  • Many classic Unix utilities can operate without requiring filenames, thereby acting as filters.
  • We are evaluating sort, wc, grep, and cat.


Concept / Approach:

sort sorts lines received from stdin or files and writes sorted output to stdout. wc counts lines, words, and bytes from stdin or files and prints results to stdout. grep filters lines matching a pattern, again from stdin or files, to stdout. cat concatenates files or stdin and writes to stdout, often used as a simple pass-through or to combine streams. All four therefore qualify as filters when used in pipelines.



Step-by-Step Solution:

Check each utility's stdin/stdout behavior: all accept stdin and produce stdout.Confirm pipeline usage: e.g., dmesg | grep error | sort | wc -l | catSince each can be used as a filter, none of them is “not a filter”.Hence the correct choice is “None of the above.”


Verification / Alternative check:

Run a simple pipeline: printf "b\na\nc\n" | sort | wc -l. Insert cat anywhere in the chain; it still reads stdin and writes stdout, proving its filter behavior in practice.



Why Other Options Are Wrong:

  • sort: Is a classic filter, not incorrect.
  • wc: Also a filter; reads from stdin fine.
  • grep: A textbook filter used for pattern matching in pipelines.
  • cat: Often used to pass data through or concatenate; behaves as a filter.


Common Pitfalls:

Thinking “cat” is not a filter because it often reads files by name; in fact, it reads stdin when no file is specified, making it a filter. Likewise, all of the listed commands can take input from stdin, aligning with the filter definition.



Final Answer:

None of the above

More Questions from Linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion