Skip to main content

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

Metadata

Release files for PyAwk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyAwk 0.1.0
File Size Uploaded Provenance Actions
PyAwk-0.1.0.tar.gz 2.8 kB Without provenance Details for PyAwk-0.1.0.tar.gz

Release files / PyAwk-0.1.0.tar.gz

Download URL PyAwk-0.1.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7d00431872da7ff2ad2a2e3e715a4f6c3d08c73df551990b830440273fb1be28
BLAKE2b-256 checksum
How to use checksums
0dda67fb172603f16e2ee37a6d412be8f4f34db0db713cfbf526b4a5ea595dbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for PyAwk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page