Recipe of the week: Pyline

by Jeremy Jones

OK - so I haven't done a "recipe of the week" in a while. But does titling the post "{{whatever}} of the week" mean that I'm going to do one of these every week, or does it mean that I promise not to do more than one per week? :-)

Anyway, I was googling around to see if a certain type of utility existed and I stumbled across this recipe for something called Pyline. Basically, Pyline allows you to pipe text to it and use Python syntax to manipulate what it will output, specifically at the word and line level. Here are a couple of examples from the recipe:

Print out the first 20 characters of every line in the tail of my
Apache access log:

tail access_log | pyline "line[:20]"

Print just the URLs in the access log (the seventh "word" in the line):

tail access_log | pyline "words[6]"

Good work Graham Fawcett. This is a useful little utility and the code is pretty brief. So, this is the recipe of this week.


Graham Fawcett
2008-01-24 20:43:52
Thanks! I'm glad you liked it -- it's may be the best 20 lines of code I ever wrote. ;-)