Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Bash, awk et al = the syntax that can't be remembered, not even when smashed in the head with a tiring iron or forced with a submachine gun.


I found the awk syntax to be surprisingly discoverable, once I got the rough structure of scripts.

I think the confusing factor with awk is that it allows you to leave out variuos levels of structure in the really simple scripts, meaning that the same scripts you see around will look quite different.

E.g. all the following would be the same (looking for the string "something" in column 1, and printing only those lines):

'$1 == "somestring"'

'$1 == "something" { print }'

'($1 == "something")'

'($1 == "something") { print }'

... to give a small example.

At least this confused me a lot in the beginning.


  awk '{print $3}'
is what cut should have been all along. Specifically, this will give you the third space delimited field, where multiple spaces are coalesced.

  cut -d ' ' -f 3 
will get you whatever is between the 3rd and 4th space.


Awk syntax is basically what became core Javascript according to its creator [1]. Bourne shell syntax is very different so I take your comment as a frustrated reaction to the "Python obsolete" comment which must be seen in context with Python introducing itself as an awk replacement among other things (though not nearly as aggressive as Perl which use to have the a2p script to bogusly convert awk to Perl code).

[1]: https://brendaneich.com/2010/07/a-brief-history-of-javascrip...


I can agree on bash syntax being crazy, but certainly not on awk. Awk is very simple, a man page is all you need if you need to find something. Otherwise what's so complex with awk?


If you don't like learning from a man page (understandable), I can recommend a quick read of the Awk book by A, K, and W. It's very short and has fun examples.


I feel there was a missed chance to make it “by A, W and K”


It's easy. You just need to stop thinking of these things as toys...

Awk + bash could easily recreate most existing code in a couple of lines


Bash is so comfortable to write in, its like you are just writing psuedocode. Pipes >>>>>>> a dozen parentheses I forget to close half the time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: