-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
7 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,12 @@ | ||
.. highlight:: bash | ||
|
||
|
||
Internals | ||
========= | ||
|
||
Unix timestamp | ||
-------------- | ||
|
||
Formats a Unix timestamp (1443214640) as a human-readable string. | ||
|
||
.. code:: bash | ||
py1 -i 'time/ctime' 'P(ctime(1443214640))' | ||
To do so we import ctime from the time module and print it. | ||
|
||
|
||
Count blank lines | ||
----------------- | ||
|
||
Count the number of blank lines in a file. | ||
|
||
.. code:: bash | ||
py1 -b 'c=0' -l 'if not L: c += 1' -e 'P(c)' | ||
Here we define an acumulator variable and increment it when the line satisfies a criteria. | ||
|
||
|
||
Print 2nd and 3rd fields | ||
------------------------ | ||
|
||
Show the second and third fields of ``/etc/passwd``, a file whose fields are separated by "``:``". | ||
|
||
.. code:: bash | ||
cat /etc/passwd | py1 -b 'WS=":"' -l 'P(W[1:2])' | ||
Here we override WS to use the "``:``" separator of ``/etc/passwd``. | ||
|
||
|
||
Show lines matching a regexp | ||
---------------------------- | ||
|
||
Show lines matching the regexp '$a+^'. | ||
|
||
.. code:: bash | ||
py1 -l 'if M("$a+^", L): P(L)' | ||
Here we use the M matching function to match the regexp. | ||
|
||
Count blank lines again | ||
----------------------- | ||
|
||
Count the number of blank lines in a file. | ||
|
||
.. code:: bash | ||
py1 -e 'P(sum(1 if l else 0 for l in F))' | ||
Here we do not set a per-line statement and instead have sum iterate over F. | ||
|
||
Group by | ||
-------- | ||
|
||
Given a file of '$name $value', with name being repeated, sum the values for each name. | ||
This describes the implementation of py1, not its usage. | ||
|
||
.. code:: bash | ||
.. autosummary:: | ||
:toctree: _autosummary | ||
|
||
py1 -b 'd=defaultdict(int)' -l 'd[W[0]] += int(W[1])' | ||
-e 'for n, v in d: P(n, v)' | ||
py1.curly | ||
py1.runner | ||
py1.template_reader | ||
py1.tty |