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

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.




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

Search: