gawk: Read Terminal

1 
1 1.1.2 Running 'awk' Without Input Files
1 ---------------------------------------
1 
1 You can also run 'awk' without any input files.  If you type the
1 following command line:
1 
1      awk 'PROGRAM'
1 
1 'awk' applies the PROGRAM to the "standard input", which usually means
1 whatever you type on the keyboard.  This continues until you indicate
1 end-of-file by typing 'Ctrl-d'.  (On non-POSIX operating systems, the
1 end-of-file character may be different.)
1 
1    As an example, the following program prints a friendly piece of
1 advice (from Douglas Adams's 'The Hitchhiker's Guide to the Galaxy'), to
1 keep you from worrying about the complexities of computer programming:
1 
1      $ awk 'BEGIN { print "Don\47t Panic!" }'
1      -| Don't Panic!
1 
1    'awk' executes statements associated with 'BEGIN' before reading any
1 input.  If there are no other statements in your program, as is the case
1 here, 'awk' just stops, instead of trying to read input it doesn't know
1 how to process.  The '\47' is a magic way (explained later) of getting a
1 single quote into the program, without having to engage in ugly shell
1 quoting tricks.
1 
1      NOTE: If you use Bash as your shell, you should execute the command
1      'set +H' before running this program interactively, to disable the
1      C shell-style command history, which treats '!' as a special
1      character.  We recommend putting this command into your personal
1      startup file.
1 
1    This next simple 'awk' program emulates the 'cat' utility; it copies
1 whatever you type on the keyboard to its standard output (why this works
1 is explained shortly):
1 
1      $ awk '{ print }'
1      Now is the time for all good men
1      -| Now is the time for all good men
1      to come to the aid of their country.
1      -| to come to the aid of their country.
1      Four score and seven years ago, ...
1      -| Four score and seven years ago, ...
1      What, me worry?
1      -| What, me worry?
1      Ctrl-d
1