1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# Written by Aleksey Cheusov <vle@gmx.net>, public domain
#
# This awk module is a part of RunAWK distribution,
# http://sourceforge.net/projects/runawk
#
############################################################
#use "xgetline.awk"
#use "xclose.awk"
# =head2 readfile.awk
#
# =over 2
#
# =item I<readfile(FILENAME)>
#
# read entire file and return its content as a string
#
# =back
#
# See example/demo_readfile for the sample of usage
#
function readfile (fn, ret){
# Unfortunately there is no way portable accross all awk flavours
# to read an entire file content by single 'getline' command.
# This is why I use loop here.
ret = ""
while (xgetline(fn)){
if (ret == "")
ret = __input
else
ret = ret "\n" __input
}
xclose(fn)
return ret
}
|