Q:

setting the NR to 1 does not work (awk)

I have the following script in bash. 
awk -F ":" '{if($1 ~ "^fall") 
                      { NR==1
                      {{printf "\t<course id=\"%s\">\n",$1} } } }' file1.txt > container.xml

So what I have a small file. If ANY line starts with fall, then I want the first field of the VERY first line.
So I did that in the code and set NR==1. However, it does not do the job!!!

A:

Try this:
awk -F: 'NR==1 {id=$1} $1~/^fall/ {printf "\t<course id=\"%s\">\n",id}' file1.txt > container.xml

Notes:

NR==1 {id=$1}
This saves the course ID from the first line
$1~/^fall/ {printf "\t<course id=\"%s\">\n",id}
If any line begins with fall, then the course ID is printed.
The above code illustrates that awk commands can be preceded by conditions.  Thus, id=$1 is executed only if  we are on the first line: NR==1.  If this way, it is often unnecessary to have explicit if statements.
In awk, assignment with done with = while tests for equality are done with ==.

If this doesn't do what you want, then please add sample input and corresponding desired output to the question.

