UNIX: Sorting & Pipe System

Lecture Overview
  • This lecture covers fundamental UNIX concepts related to input/output streams, file redirection, and piping between programs. These mechanisms are crucial for creating flexible and modular command-line workflows.

  • The objective is to combine these tools to create powerful and efficient command-line functionalities by chaining simple utilities.

Useful UNIX Utilities
wc (word count)
  • Functionality: Reports the number of lines, words, and characters (bytes) present in a given file or read from standard input.

  • Applicability: While wc can process any file type, its counts for lines and words are most meaningful for human-readable text files. For binary files, it accurately reports the byte count, but line and word counts will typically be zero.

  • Utility: It's a versatile tool for quick data assessment, text analysis, and scripting, enabling users to gain immediate insights into a file's size and textual structure.

  • Requirement: By default, wc reads from standard input (stdin) if no file argument is provided. To operate on the content of a file or the output of another command, it often leverages file redirection (e.g., < for input from a file) or piping (|) for input from another process.

  • Example Usage:

    • To view the content of TextFile, one might use cat TextFile. If TextFile contains:
      Hello world. This is a test. Another line. End of file.
      Then, wc TextFile would output 4 13 54 TextFile. (Here, 4 lines, 13 words, 54 characters, assuming standard character encoding and no trailing newlines affecting word count).

    • When attempting wc /bin/kill on a binary executable file like /bin/kill, the output might look like 0 0 16864 /bin/kill. This indicates 0 lines, 0 words (as these concepts don't apply to raw binary data in the same way), but accurately reports the size of the file in bytes (e.g., 16864 bytes).