Let me try and answer your questions. If you are new to awk and would like to learn more, here is a good book that I can recommend:
sed & awk, Second Edition - O'Reilly Media
Quote:
questions:
3. 'BEGIN {c=0}
Why do that? I don't see a 'c' variable anywhere else. When I googled this, you seem to do something like this when you add:
I see no big reason to do this, in this case. A BEGIN block executes (as the name implies) right at the beginning, before anything else is done. All that it is doing is assigning a value to 0 to the var c - which is not even being used in your code.
Quote:
4. { i=1; while ( i <= NF )
This a loop. that runs until the end of the line.
5. { f=$i;
didn't they just set i=1, and then increment it.
if f=$i, shouldn't that be a number instead, it appears it is what is actually in that field?
The script is iterating (in the while loop) over each of the fields in the input that you pass to your script. So, $i the first time will refer to field 1 and $i the second time will refer to field 2 and so on - until NF, the total number of fields.
Quote:
6. if ( f == "CREATE" )
condifitional logic
7. printf("\n\nPROMPT %s \n",$0);
short hand of the "then" part of conditional logic
You are correct. If one of the fields has a value of CREATE, it prints the whole line preceded by PROMPT. The %s argument to
printf if a format specifier which tell it print the arg as string.
Quote:
8. I see a -o, is that an "or" ? This is from a new line.
if ( ( f == "HERE" ) \
-o ( f == "THERE" ) \
-- if here or there? right?
-- why do we need "\", I know that means continue on a new line ,but why is that necessary here?
You are correct about the -o. The "\" is to indicate that the current statement continue on the next line - basically, it is an escape for the newline character.
Quote:
-o ( substr(f,length(f)-6,7) == "START" ) \
Bit unclear about this myself. It seems to be looking at the last 7 characters of the field f, but comparing it with the string START. I guess the intent is to see if the field ends with START.
Hope this helps!!
-GP