{"id":18403742,"url":"https://github.com/russellluo/pyawk","last_synced_at":"2025-04-12T19:11:44.576Z","repository":{"id":11537634,"uuid":"14022356","full_name":"RussellLuo/pyawk","owner":"RussellLuo","description":"A simple variant of AWK in Python.","archived":false,"fork":false,"pushed_at":"2013-10-31T16:35:04.000Z","size":112,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-16T04:17:09.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RussellLuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-31T16:32:18.000Z","updated_at":"2024-12-06T19:49:46.000Z","dependencies_parsed_at":"2022-08-19T08:32:43.489Z","dependency_job_id":null,"html_url":"https://github.com/RussellLuo/pyawk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyawk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyawk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyawk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyawk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RussellLuo","download_url":"https://codeload.github.com/RussellLuo/pyawk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618281,"owners_count":21134201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:48:04.722Z","updated_at":"2025-04-12T19:11:44.557Z","avatar_url":"https://github.com/RussellLuo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"PyAWK\n=====\n\nA simple variant of AWK in Python.\n\n1| Motivation\n-------------\n\nKeep **simple**, **wonderful** and **the most frequently used** features in `awk`, while replacing the **complicated** and **ambiguous** syntax with `Python`. As a result, we can get the power of both `Python` and `awk` by using `pyawk`, a pythonic awk.\n\n2| pyawk vs awk\n---------------\n\n+ **usage**\n\n    pyawk:\n    \n        pyawk [option] 'pattern { action }' file\n    \n    awk:\n    \n        awk [option] 'pattern { action }' file1 file2 ...\n\n+ **option**\n\n    pyawk        | awk                    | Remarks\n    ------------ | ---------------------- | -------\n    -F fs        | -F fs                  |\n    -f progfile  | -f progfile            | (1)\n    -v (verbose) | -v var=val             |\n    ×            | other options in `awk` |\n\n    (1) In `pyawk`, \"progfile\" is actually a Python module, in which all commands are included in a list called `cmds`. While \"progfile\" is just a normal text file in `awk`.\n\n+ **pattern**\n\n    pyawk                             | awk                               | Remarks\n    --------------------------------- | --------------------------------- | -------\n    /regex/ \u003c=\u003e $0/regex/             | /regex/ \u003c=\u003e $0 ~ /regex/          | (1)\n    $1/regex/                         | $1 ~ /regex/                      | (1)\n    $1!/regex/                        | $1 !~ /regex/                     | (1)\n    all valid expressions in `Python` | all valid expressions in `awk`    | (2)\n    begpat, endpat                    | begpat, endpat                    | (3)\n    BEGIN { action }                  | BEGIN { action }                  | (4)\n    END { action }                    | END { action }                    | (4)\n    no pattern \u003c=\u003e match every record | no pattern \u003c=\u003e match every record | (5)\n    ×                                 | other patterns in `awk`           |\n\n    (1) regular expression\n\n    (2) expression\n\n    (3) begpat, endpat\n\n    (4) BEGIN/END\n\n    (5) empty\n\n+ **action**\n\n    pyawk                            | awk\n    -------------------------------- | -------------------------------\n    all valid statements in `Python` | all valid statements in `awk`\n    print($1, $2, $3)                | print $1, $2, $3\n    no action \u003c=\u003e `print($0)`        | no action \u003c=\u003e `print $0`\n    `print` (×, must be `print($0)`) | `print` (√, \u003c=\u003e `print $0`)\n    ×                                | variables used before defined\n\n+ **built-in variable**\n\n    pyawk | awk                               | Remarks\n    ----- | --------------------------------- | -----------------------\n    NR    | NR                                | Number of Records\n    NF    | NF                                | Number of Fields\n    FS    | FS                                | input Field Separator\n    RS    | RS                                | input Record Separator\n    OFS   | OFS                               | Output Field Separator\n    ORS   | ORS                               | Output Record Separator\n    ×     | other built-in variables in `awk` |\n\n3| Usage\n--------\n\n### 1) Install\n\n    sudo python setup.py install\n\n### 2) Uninstall\n\n    sudo python setup.py uninstall\n\n### 3) Examples\n\nSee help message of command `pyawk`:\n\n    pyawk 'END { print(NR) }' /etc/passwd\n    echo -e 'python .py\\nperl .pl\\nshell .sh' | pyawk '$2!/pl/{ print($1) }'\n    ps aux | pyawk 'BEGIN { print(\"USER|PID|COMMAND\") }; $2 == 10, $2 == 50 { print($1, $2, $11) }'\n\nSee directory `sample`:\n\n    pyawk -f sample.cmds sample/data.txt\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellluo%2Fpyawk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frussellluo%2Fpyawk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellluo%2Fpyawk/lists"}