Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A framework which makes you to write scripts as if they were written in awk.

Project Description

All you have to do is make a script file and create a class which extends PyAwk class and write some procedures like awk.

There are some examples on https://github.com/hideshi/PyAwk.

Requirements

  • Python 3.3 or later

Features

  • begin and end syntax which are called only once in an execution.
  • begin_file and end_file syntax which are called only once par each file.
  • awk specific valiables like FILENAME, FS, OFS, RS, ORS, NF, NR, FNR, FIELDWIDTHS.
  • command line options like debug mode, set valiables.
  • SQLite3 query.

Setup

$ pip install PyAwk

History

0.1.0 (2014-02-21)

  • first release

Example

This is a parser for LTSV formatted data. http://ltsv.org

#!/usr/bin/env python3.3
from pyawk import PyAwk, p
class LTSVParser(PyAwk):
    def begin(self):
        self.FS = '\t'
        self.count = 0

    def action(self, S):
        if not p(S[0], r'status:200'):
            self.count += 1
            self.print('----------')
            d = {}
            for elem in S[1:]:
                key, value = elem.split(':', 1)
                d[key] = value
            self.print(d)

    def end(self):
        self.print('----------')
        self.print('Total:{}'.format(self.NR))
        self.print('Matched:{}'.format(self.count))

if __name__ == '__main__':
    LTSVParser().run()

Then you can execute this script with LTSV file.

$ ./ltstparser.py ltsv.log
Release History

Release History

This version
History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
PyAwk-0.1.0.tar.gz (2.8 kB) Copy SHA256 Checksum SHA256 Source Feb 21, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting