[Home]
HomePage RecentChanges Frequently Asked Questions

redirection

The awk scripting language provides support for redirection via the greaterthan, doublebeak and pipe symbols. The greaterthan symbol acts as an output redirection operator allowing output from a function to be written to a named file. If the named file exists, its contents will be overwritten by the output from the function:

 BEGIN {
 # Creates a file foobar.txt
 # If the file already exists, its contents will be overwritten
 print "Hello" > foobar.txt
 }

A doublebeak symbol behaves in a similar manner to the greaterthan symbol, but instead of the file being overwritten, the output from the function will be appended to the end of the file:

 BEGIN {
 # Append a message to the end of the file foobar.txt
 print "Hello" >> foobar.txt
 }

Redirection to standard error

The traditional way to redirect output to standard error is by using a kludge to pipeline redirection to an external cat command:

 print "TST60000 An error has occured!" | "cat 1>&2"

On systems that provide /dev/stderr, redirection can be made to this device:

 print "TST60000 An error has occured!" > /dev/stderr

Edit this page View other revisions Administration
Last edited 2011年06月25日 05:12 UTC by pgas (diff)

Powered by sdf Creative Commons License <pierre.gaston+awk@gmail.com>

Awk Wiki by #awk is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

AltStyle によって変換されたページ (->オリジナル) /