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
awkprogramming 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 ifxis less thanyx <= y-> True ifxis less than or equal toyx > y-> True ifxis greater thanyx >= y-> True ifxis greater than or equal toyx == y-> True ifxis equal toyx != y-> True ifxis not equal toyx ~ y-> True if the stringxmatches the regexp denoted byyx !~ y-> True if the stringxdoes not match the regexp denoted byysubscript in array-> True if the arrayarrayhas an element with the subscriptsubscript
Boolean Expressions
boolean1 && boolean2boolean1 || 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
Cand/orC++(ingawkonly???)
# 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.inArray 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!