Gladly, we all started at some point.
The printf() function takes a format string as it's first parameter. This is used to determine the number of parameters, and their types, that follow. The manual page for the shell version does a wonderful job of explaining the details:
Man Page for printf (OpenSolaris Section 1) - The UNIX and Linux Forums
In brief, the percent sign followed by one or more characters, indicates the position that the next parameter is to be placed into the output. %d is integer, %s is string, %f is floating point decimal, etc. So, the format string "Today is %s the %d day of %s\n"
would fill in the day of the week (first %s), the day of the month (%d) and the month (last %s) using the parameters. This assumes that the values are properly assigned to variables passed to the function. The following may help:
day=22;
month="May";
wday="Tue";
printf( "Today is %s the %d day of %s\n", wday, day, month );
This is a silly example, but I think it works to show how it goes.
The \n
represents a newline character causing the next output written after this to be placed at the start of a new line. In the bit of code I wrote, I took advantage that without the new line, all three values are written on the same line, and then a final new line is written after the loop is done.
I also took avantage of a property of awk's printf with the integers. The fields were actually nn;
and by using %d to print them, awk converted the string to integer and thus the trailing semicolon was removed.
The printf() function is wonderful and is supported in awk, shells and C/C++. Each function pretty much the same, but there are subtle differences like the automatic conversion of a string to integer by awk. Check out the manual page above, and the one for the C function to learn more.