READFILE(3am)
β¨ READFILE(3am) β¨
okay bestie, sit DOWN, because this is readfile β a little extension from the GNU Awk Extension Modules family, and she is, lowkey, the moment. π
π NAME π
readfile β she returns the entire contents of a file as a string. that's it. that's the whole job. and she eats every time. π
π¦ SYNOPSIS π¦
@load "readfile"
result = readfile("/some/path")
and if you want whole files to be treated as single records (yes, the whole file as ONE record, main character energy π):
@load "readfile"
BEGIN { PROCINFO["readfile"] = 1 }
π DESCRIPTION π
so the readfile extension adds literally one function, named readfile(). iconic of her, honestly β no bloat, no drama.
- the argument is the name of the file you wanna read π
- the return value is a string holding the entire contents of the file you asked for π
β οΈ and if something goes wrong?? she returns the empty string and setsERRNO. no cap. so CHECK YOURERRNO, bestie, do not just trust the empty string π
oh and ALSO β she adds an input parser. it gets activated if PROCINFO["readfile"] exists. when it's on, each input file comes back in its entirety as $0, and RT is set to the null string. yes, RT is empty. that's the vibe. π
πΈ EXAMPLE πΈ
@load "readfile"
...
contents = readfile("/path/to/file");
if (contents == "" && ERRNO != "") {
print("problem reading file", ERRNO) > "/dev/stderr"
...
}
see how she checks contents == "" AND ERRNO != "" together?? that's the pattern, babe. that's how you catch a fail before it catches you. π«Ά
β SEE ALSO β
GAWK: Effective AWK Programmingβ go read it, fr fr π- and the man pages for the other extensions shipped with
gawkπ¦
π AUTHOR π
Arnold Robbins, arnold@skeeve.com. absolute legend behavior, ty for your service π«‘
π COPYING PERMISSIONS π
Copyright Β© 2012, 2013, 2014, 2018, 2026, Free Software Foundation, Inc.
- Permission is granted to make and distribute verbatim copies of this manual page, provided the copyright notice and this permission notice are preserved on all copies.
- Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
- Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.
and that's the whole page, bestie!! this beauty came from the Free Software Foundation and she's dated Feb 25 2026 β READFILE(3am), that's her whole government name. go read some files. slay. πβ¨π
π¦ where this page comes from
- arch rolling: gawk 5.4.1-1 Β· GPL-3.0-or-later
- nixos 26.05: gawk-interactive 5.4.1
- nixpkgs unstable: gawk 5.4.1
- nixpkgs unstable: gawk-interactive 5.4.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms