In this lecture we talk about a variable assignment and how to do Maat operations with variables assignment
is pretty simple and it's the same as you know for a beshe when we go on for example into variable A
assign value one and we use a equal sign one for string assignment when we want to assign a word or
a sentence.
We are using quotation marks if we want increment value of variable A.
We just use plus plus or we can use a equal sign a plus one.
The most common mud operations are very easy as you can see.
Also we have more a matter of patience available for awk.
But in most cases you will not need to then we can now practice some basic math and as now we won't
do any file in both just live with the same as me in the BEGIN section and one plus one and we see that
this is working.
Outproduce is 2 now in six minus 1
result is 5.
We can do also easily some division
and does all operates.
Floating point
yes it does.
And we can also try to do some multiplication.
So any type of operation can be done here.
This is amazing.
Now let's print number of records in a passport file and as a record separator I will use newline character.
So in the BEGIN section I will define a record separator as a new line
and in N.S. either print number of records.
So in my case I have 41 record forty one lines.
Now let's create a variable count inside BEGIN section.
So in BEGIN section we will have a record separator which is equal to no line and you will have also
a variable called
which is equals to zero.
And for each record be will increase counter the value by 1 in the main body section
and in the section will print number of records.
And also we'll print a variable count
in the N.S. number of records and value of variable count should be the same because they are doing
the same for each record.
They increase in value by 1 and I can see same numbers here.
Great.
Now let's increase our variable count for each record by 2 instead of by only 1
and we see that the variable count has now its value two times bigger than number of records.
Great.