I have the following input file:

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
0F2F77F472  4343854 Fri Oct  7 10:13:41  [email protected]
(host redacted.host.com[x.x.x.x] said: 452 4.2.2 Over quota (in reply to end of DATA command))
                                         [email protected]

03A017F486   992790 Fri Oct  7 13:09:44  [email protected]
(host host.redacted.net[y.y.y.y] said: 452-4.2.2 The email account that you tried to reach is over quota. Please direct 452-4.2.2 the recipient to 452 4.2.2  redacted (in reply to RCPT TO command))
                                         [email protected]

In my AWK script, I wrote something like this:

  RS = "\n\n"

  ... do something ...

The header would get processed as well, so in my pipeline, before passing to the AWK, I do:

... | tail +2 | awk -f script

I acknowledged that to skip the very first line in AWK, mostly, is by doing this simple trick:

  if (NR > 1) {

It should work but the RS = "\n\n" that I set in the BEGIN block, would make the first record be ignored (AWK interprets the header as part of the first record).


$ awk 'BEGIN { RS = "\n\n" } { print NF }' sample

$ awk 'BEGIN { RS = "\n\n" } NR > 1 { print NF }' sample

Is there any way that I can achieve the goal without relying on any external tool?

GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
  • Why the downvotes?
    – annahri
    Oct 12, 2022 at 2:05

1 Answer 1


Using any awk:

$ awk 'NR==1{RS=""; next} {print NF}' file

When you use RS = "\n\n" the behavior is undefined by POSIX and so then you need to use GNU awk or any other awk which specifically supports multi-char RS (read the man page for your awk). If, on the other hand, you use RS = "" that IS defined by POSIX as puting awk into paragraph mode where each record is separated from the next by blank lines.

Not setting RS until after the first line is read lets us easily read and discard that line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .