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 sets ERRNO. no cap. so CHECK YOUR ERRNO, 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