filename: awkslurp.txt author: Eric Pement date: March 26, 2003 How to slurp up whole files in awk ================================== To slurp up an entire file at once in awk, set the RS (record separator) variable to an unused character that is not in the file. E.g., BEGIN { RS = "\f" } # \f is formfeed or Ctrl-L However, if you plan to pass multiple files on the command-line to awk, like this: awk -f myscript.awk file* awk 'BEGIN{RS="\f"}; {more-to-come...}' file* you may also need a way to cycle through each file one at a time. It is NOT possible to use the END{...} block in awk, since the END{...} block is invoked only once, after all the files have been read. Therefore, a different technique must be used. If reading whole files, use the FNR variable, which is like NR (number of the current record) relative to the current file. Thus, when FNR==1 in slurp mode, you know that the entire file has been read. Thus, here is an example: BEGIN{ RS = "\f" } FNR==1 && /foo.*bar/ { print "Both terms occur in " FILENAME } which can be invoked like this: awk -f myscript.awk file* [eof]