Giter Club home page Giter Club logo

awk-lesson's People

Contributors

billmills avatar bolaram avatar wking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

awk-lesson's Issues

The regular expression for FS is wrong

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).

Assigning to FS is problematic

In lesson.md after -F is introduced, we have:

{FS="[/ :]"}

This is problematic:

  • This code is executed for every line of input, but the way it's introduced it looks like it only runs once (of course, in this case it isn't a problem, because repeating the assignment has the same effect).
  • The assignment doesn't take place until after the first line is split. In this case you're not processing the first line, so you can't see the effect that this has. But if you do something like this: 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 is not idiomatic

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.