I wish to understand awk. (At least to some degree of competence).
I asked 'duckduck-go' if awk was a command and a program. It appears it is both (or either).
With that trivia out of the way, I proceed to my "Q".
First, I must explain that the variables $FIPA and $INFIL are (together) a string variable that (when concatenated) will 'find' my data-file. To re-iterate: The file reference is legit.
Now consider this single-line command:
Code: Select all
gawk ' 1 {print NR, $3}' $FIPA$INFIL
Each line in the file is printed to the terminal.
Next, consider the command:
Code: Select all
gawk 'if(1) {print NR, $3}' $FIPA$INFIL
gawk: cmd. line:1: if(1) {print NR, $3}
gawk: cmd. line:1: ^ syntax error.
Adding curly braces solves the problem-o:
# gawk '{if(1) {print NR, $3}}' $FIPA$INFIL
1
2 Holland
3 Mexico
4 France
5 Spain
6 Italy
I read this info while I tried to understand the syntax:
"Curly braces in awk enclose the action part of the pattern {action} pair. As you don't supply any pattern, the result is FALSE and nothing is acted. Without the braces, it's a pattern which on second encounter is TRUE, so the default action (print $0) is executed."
Fr. https://www.unix.com/shell-programming- ... eeded.html
I'm using gawk, from uPupBB. Maybe the syntax (in awk) is different from the para above?
At any rate, I fail to understand the function (or purpose) of curly braces and (perhaps even) the semicolon separator. Can anyone give me a link of elucidation so I may be wise in the ways of awk?
Собака