Kenny McCormack
unread,Mar 27, 2015, 8:52:47 AM3/27/15You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Here's a version I just threw together that uses the (as yet still
unpublished) "call_any" extension library.
Just though y'all might find it interesting...
--- Cut Here ---
# readfile1.awk
# This is the gist of it; TODO: add (better) error checking...
@load "call_any"
function readfile1(fn, fd,fs,buff) {
if ((fd = call_any("isi","open",fn,0)) == -1) return "### ERROR ###"
fs = call_any("iiii","lseek",fd,0,2)
# print "fn:",fn,"fd:",fd,"fs:",fs
buff = sprintf("%*s",fs,"")
call_any("iisii","pread",fd,buff,fs,0)
call_any("ii","close",fd)
return buff
}
--- Cut Here ---
Note also, a possible TODO is to add the following line right before the
final "return":
sub(/\n$/,"",buff)
The idea is that I almost always use readfile1() like this:
split(readfile1("someFile"),A,"\n")
which results in an extra empty field at the end. In fact, an idiom that I
now find myself using is:
delete A[split(readfile("someFile"),A,"\n")]
But, of course, having the function itself remove the extra newline is
better.
Anyway, enjoy!
--
They say compassion is a virtue, but I don't have the time!
- David Byrne -