I finally finished section 6 from the awk
manual and I discovered that Hacker Rank has an entire section on Linux Challenges!
TLDR;
Okay, so here are the highlights of what I did:
- I watched the YouTube recording of lecture 4 of the MIT Missing Semester Course. I wanted to see if I could take more information away now that I have practiced with all of the tools mentioned a bit. I learned a bit more but it was a great revision overall.
- I continued with my notes on the
awk
programming language. I finished section 6 which is kind of a big deal. Section 6 is a pretty big seciton. I will start section 7 if I feel like I need to learn more.
Notes from gawk
manual – Expressions
Comparison Operators
Comparison expressions have the value one if true and zero if false.
x < y
-> True ifx
is less thany
x <= y
-> True ifx
is less than or equal toy
x > y
-> True ifx
is greater thany
x >= y
-> True ifx
is greater than or equal toy
x == y
-> True ifx
is equal toy
x != y
-> True ifx
is not equal toy
x ~ y
-> True if the stringx
matches the regexp denoted byy
x !~ y
-> True if the stringx
does not match the regexp denoted byy
subscript in array
-> True if the arrayarray
has an element with the subscriptsubscript
Boolean Expressions
boolean1 && boolean2
boolean1 || boolean2
! boolean
Conditional Expressions (ternary Operator in JavaScript)
# syntax
selector ? if-true-exp : if-false-exp
6.4 Function Calls
gawk
has:
- built-in functions
- custom functions that we can write in
awk
- functions we can import from
C
and/orC++
(ingawk
only???)
# syntax
sqrt(x^2 + y^2) one argument
atan2(y, x) two arguments
rand() no arguments
6.5 Operator Precedence
BEDMASS/PEMDAS Math operations applies in awk
as well.
A list of precedence for all awk
operators:
(…)
Grouping.$
Field reference.++ --
Increment, decrement.^
Exponentiation. These operators group right to left.+ - !
Unary plus, minus, logical “not.”* / %
Multiplication, division, remainder.+ -
Addition, subtraction.- String concatenation e.g.
("hello" " world")
< <= == != > >= >> |
Relational and redirection. Note that the I/O redirection operators in print and printf statements belong to the statement level, not to expressions. The redirection does not produce an expression that could be the operand of another operator. As a result, it does not make sense to use a redirection operator near another operator of lower precedence without parentheses. Such combinations (e.g.,print foo > a ? b : c
) result in syntax errors. The correct way to write this statement isprint foo > (a ? b : c)
.~ !~
Matching, nonmatching.in
Array membership.&&
Logical “and.”||
Logical “or.”?:
Conditional. This operator groups right to left.= += -= *= /= %= ^=
Assignment. These operators group right to left.
Conclusion
That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!