billmills / awk-lesson Goto Github PK
View Code? Open in Web Editor NEWan introduction to awk
License: MIT License
an introduction to awk
License: MIT License
Short version: FS
should be [/ :]+
not [/ :]
.
Long version:
On lines 4, 5, and 7 of earthquakes.dat
$10
will be an empty string because their is a double space in the input file. Try changing print $3
to print $3, $10
to illustrate this.
You don't notice this because it only happens when the depth is an integer less than 10 and in awk "" < 10
(the empty string is mostly treated like 0).
In lesson.md
after -F
is introduced, we have:
{FS="[/ :]"}
This is problematic:
awk '{FS="[/ :]"}{print $1}' /etc/passwd | sed 9q
you can see that the first line isn't split.You don't get either of these problems when you use the -F
option, so I would just do:
awk '-F[/ :]+' '{if (NR > 1) print $3}' earthquakes.dat
instead (the extra +
fixes a different bug that I'm about to write up).
The awk code isn't idiomatic and looks unusual to awk programmers (like me).
For example: '{if (NR > 1) print $3}'
would really be better as:
NR > 1 { print $3 }
(there is a rough equivalence between these two forms). This changes the pedagogy a bit, but I love awk, so I'm prepared to submit a Pull Request if you're okay with that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.