1READFILE(3am)              GNU Awk Extension Modules             READFILE(3am)
2
3
4

NAME

6       readfile - return the entire contents of a file as a string
7

SYNOPSIS

9       @load "readfile"
10
11       result = readfile("/some/path")
12
13       For making whole files be single records:
14
15       @load "readfile"
16       BEGIN { PROCINFO["readfile"] = 1 }
17

DESCRIPTION

19       The  readfile  extension  adds a single function named readfile().  The
20       argument is the name of the file to read.  The return value is a string
21       containing the entire contents of the requested file.
22
23       Upon error, the function returns the empty string and sets ERRNO.
24
25       In   addition,   it   adds   an  input  parser  that  is  activated  if
26       PROCINFO["readfile"]  exists.   When  activated,  each  input  file  is
27       returned in its entirety as $0.  RT is set to the null string.
28

EXAMPLE

30       @load "readfile"
31       ...
32       contents = readfile("/path/to/file");
33       if (contents == "" && ERRNO != "") {
34           print("problem reading file", ERRNO) > "/dev/stderr"
35           ...
36       }
37

SEE ALSO

39       GAWK:   Effective   AWK   Programming,   filefuncs(3am),  fnmatch(3am),
40       fork(3am),  inplace(3am),  ordchr(3am),  readdir(3am),  revoutput(3am),
41       rwarray(3am), time(3am).
42

AUTHOR

44       Arnold Robbins, arnold@skeeve.com.
45

COPYING PERMISSIONS

47       Copyright © 2012, 2013, 2014, 2018, Free Software Foundation, Inc.
48
49       Permission  is  granted  to make and distribute verbatim copies of this
50       manual page provided the copyright notice and  this  permission  notice
51       are preserved on all copies.
52
53       Permission  is granted to copy and distribute modified versions of this
54       manual page under the conditions for verbatim  copying,  provided  that
55       the  entire  resulting derived work is distributed under the terms of a
56       permission notice identical to this one.
57
58       Permission is granted to copy and distribute translations of this  man‐
59       ual page into another language, under the above conditions for modified
60       versions, except that this permission notice may be stated in a  trans‐
61       lation approved by the Foundation.
62
63
64
65Free Software Foundation          Feb 02 2018                    READFILE(3am)
Impressum