Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Using the less program's search function is one way to find text in a file, but especially when you want to see the context surrounding the searched-for text. But for general text searching, the grep program is used much more frequently for text searching.

The word grep stands for general regular expression parser, and nearly every programming language offers grep functionality, where a pattern you specify – a regular expression or regex – describes how the search is performed.

...

  1. In the 1st, the more command reads some input from the jabberwocky.txt file
    • then writes the output to standard output, which is displayed on your Terminal
    • it pauses at page boundaries (--More--) waiting for input on standard input
    • when it receives a space on on standard input it reads more input from jabberwocky.txt
    • then writes the output to standard output, which is displayed on your Terminal
  2. In the 2nd, the cat command reads its input from the jabberwocky.txt file
    • then writes its output to standard output
    • the pipe operator ( | ) then connects the standard output from cat to standard input
    • the more command then reads its input from standard input, instead of from a file
      • then writes its output to standard output, which is displayed on your Terminal
      • more continues its processing as described in #1
      Note that
      • similar to #1, except reading from standard input instead of the file

Notes:

  • In #2, the cat command "blocks" writing to its standard output until more says it's ready for more input

      ...

        • This "write until block" / "read when input available" behavior makes streams a very efficient means of inter-process communication.
      • In #1, more can report how much of the file has been read, e.g. --More-- (24%) because it has access to the size information for the file it is reading.
        • But in #2, the text is "anonymous" – from standard input – so more doesn't know how much of the total has been provided.

      Excercise 2-3

      Use the pipe operator to provide jabberwocky.txt data to the less command so that line numbers are displayed.

      ...