{
    "mode": "man",
    "parameter": "READFILE",
    "section": "3am",
    "url": "https://www.chedong.com/phpMan.php/man/READFILE/3am/json",
    "generated": "2026-09-16T01:43:03Z",
    "synopsis": "@load \"readfile\"\nresult = readfile(\"/some/path\")\nFor making whole files be single records:\n@load \"readfile\"\nBEGIN { PROCINFO[\"readfile\"] = 1 }",
    "sections": {
        "NAME": {
            "content": "readfile - return the entire contents of a file as a string\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "@load \"readfile\"\n\nresult = readfile(\"/some/path\")\n\nFor making whole files be single records:\n\n@load \"readfile\"\nBEGIN { PROCINFO[\"readfile\"] = 1 }\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  readfile extension adds a single function named readfile().  The argument is the name of\nthe file to read.  The return value is a string containing the entire  contents  of  the  re‐\nquested file.\n\nUpon error, the function returns the empty string and sets ERRNO.\n\nIn  addition, it adds an input parser that is activated if PROCINFO[\"readfile\"] exists.  When\nactivated, each input file is returned in its entirety as $0.  RT is set to the null string.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "@load \"readfile\"\n...\ncontents = readfile(\"/path/to/file\");\nif (contents == \"\" && ERRNO != \"\") {\nprint(\"problem reading file\", ERRNO) > \"/dev/stderr\"\n...\n}\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "GAWK: Effective AWK Programming, filefuncs(3am), fnmatch(3am), fork(3am), inplace(3am),  ord‐\nchr(3am), readdir(3am), revoutput(3am), rwarray(3am), time(3am).\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Arnold Robbins, arnold@skeeve.com.\n",
            "subsections": []
        },
        "COPYING PERMISSIONS": {
            "content": "Copyright © 2012, 2013, 2014, 2018, Free Software Foundation, Inc.\n\nPermission is granted to make and distribute verbatim copies of this manual page provided the\ncopyright notice and this permission notice are preserved on all copies.\n\nPermission  is granted to copy and distribute modified versions of this manual page under the\nconditions for verbatim copying, provided that the entire resulting derived work is  distrib‐\nuted under the terms of a permission notice identical to this one.\n\nPermission  is  granted  to copy and distribute translations of this manual page into another\nlanguage, under the above conditions for modified versions, except that this  permission  no‐\ntice may be stated in a translation approved by the Foundation.\n\nFree Software Foundation                     Feb 02 2018                               READFILE(3am)",
            "subsections": []
        }
    },
    "summary": "readfile - return the entire contents of a file as a string",
    "flags": [],
    "examples": [
        "@load \"readfile\"",
        "...",
        "contents = readfile(\"/path/to/file\");",
        "if (contents == \"\" && ERRNO != \"\") {",
        "print(\"problem reading file\", ERRNO) > \"/dev/stderr\"",
        "..."
    ],
    "see_also": [
        {
            "name": "filefuncs",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/filefuncs/3am/json"
        },
        {
            "name": "fnmatch",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/fnmatch/3am/json"
        },
        {
            "name": "fork",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/fork/3am/json"
        },
        {
            "name": "inplace",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/inplace/3am/json"
        },
        {
            "name": "chr",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/chr/3am/json"
        },
        {
            "name": "readdir",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/readdir/3am/json"
        },
        {
            "name": "revoutput",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/revoutput/3am/json"
        },
        {
            "name": "rwarray",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/rwarray/3am/json"
        },
        {
            "name": "time",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/time/3am/json"
        }
    ]
}