Running awk Without Input Files【每日一译】--20130204

来源:互联网 发布:大数据开源项目 编辑:程序博客网 时间:2024/05/17 01:09

You can also runawk without any input files. If you type the following command line:

可以没有输入文件参数的使用AWK,如果你输入以下的命令行:

     awk 'program'

awk applies the program to the standard input, which usually means whatever you type on the terminal. This continues until you indicate end-of-file by typingCtrl-d. (On other operating systems, the end-of-file character may be different. For example, on OS/2, it isCtrl-z.)

awk编程对应用于标准输入,一般是指我们经常输入在终端的内容。它持续到你输入结束文件的指示命令通过输入”CTRL-D“(在其它操作系统,结束文件的标识符可能不同如在OS/2操作系统中为"CTRL-Z";

As an example, the following program prints a friendly piece of advice (from Douglas Adams'sThe Hitchhiker's Guide to the Galaxy), to keep you from worrying about the complexities of computer programming7 (BEGIN is a feature we haven't discussed yet):

举例,以下的程序输入一个友好的提示条,为了让于免于担心复杂的电脑编程(BEGIN是一个功能目前我们还未讨论到):

     $ awk "BEGIN { print \"Don't Panic!\" }"     -| Don't Panic!

This program does not read any input. The ‘\’ before each of the inner double quotes is necessary because of the shell's quoting rules—in particular because it mixes both single quotes and double quotes.8

这个程序不读入任何输入文件。“\"符号在每个内双引前是必须的,因为在SHELL中的引号语法规定的---尤其是它混合了双引和单引的情况;

原创粉丝点击