# AWK not processing BEGIN directive

**URL:** <https://community.unix.com/t/awk-not-processing-begin-directive/220495>\
**Category:** Shell Programming and Scripting\
**Created:** [November 13, 2008, 2:14pm UTC](https://community.unix.com/t/awk-not-processing-begin-directive/220495 "2008-11-13T14:14:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojoman](https://community.unix.com/letter_avatar/mojoman/32/5_5575768a8748004e209b776fc1b2916d.png) [@mojoman](https://community.unix.com/u/mojoman)\
**Post date:** [November 13, 2008, 2:14pm UTC](https://community.unix.com/t/awk-not-processing-begin-directive/220495/1 "2008-11-13T14:14:50Z")

</div>

Hello I have the following awk script:

```nohighlight
BEGIN {
        {FS = " " }
        {print "\t\tIllegal Loggon Attempts on MAIL\n"}
        {"date" | getline d}
        {printf "\t %s\n",d }
        {print "Loggon Name\t\t\t Number of Attempts\n"}
        {print"================================================\n"}
       }

{printf "%-28s\t%s\n", $2, $1 }

```

I call it from a shell script using the following command:

awk -f processing.awk names2.tmp \> email.tmp

awk reports no error but it seems that the entire BEGIN clause is not processed only the {printf "%-28s\t%s\n", $2, $1 }. And I do need the header to print. I tried commenting out {printf "%-28s\t%s\n", $2, $1 } and then the header prints! It seems that somehow the final directive is overwriting the BEGIN clause. Can someone tell me how to fix this problem?

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [November 13, 2008, 2:49pm UTC](https://community.unix.com/t/awk-not-processing-begin-directive/220495/2 "2008-11-13T14:49:59Z")

</div>

Cannot reproduce, what platform and awk version/implementation is this?

---

<div class="post-metadata">

**Author:** ![paresh\_n\_doshi](https://community.unix.com/letter_avatar/paresh_n_doshi/32/5_5575768a8748004e209b776fc1b2916d.png) [@paresh\_n\_doshi](https://community.unix.com/u/paresh_n_doshi)\
**Post date:** [November 14, 2008, 4:21am UTC](https://community.unix.com/t/awk-not-processing-begin-directive/220495/3 "2008-11-14T04:21:52Z")

</div>

try this

BEGIN {  
{FS = " " }  
{print "\t\tIllegal Loggon Attempts on MAIL\n"}  
{command = "date" | getline d}  
{printf "\t %s\n",d }  
{print "Loggon Name\t\t\t Number of Attempts\n"}  
{print"================================================\n"}  
}
