Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Pyline is a grep-like, sed-like, awk-like command-line tool for line-based text processing in Python.
GitHub
_ |
PyPi
_ |
Warehouse
_ |
ReadTheDocs
_ |
Travis-CI
_
.. image:: https://badge.fury.io/py/pyline.png :target: http://badge.fury.io/py/pyline
.. image:: https://travis-ci.org/westurner/pyline.png?branch=master :target: https://travis-ci.org/westurner/pyline
.. .. image:: https://pypip.in/d/pyline/badge.png .. :target: https://pypi.python.org/pypi/pyline
.. _GitHub: https://github.com/westurner/pyline .. _PyPi: https://pypi.python.org/pypi/pyline .. _Warehouse: https://warehouse.python.org/project/pyline .. _ReadTheDocs: https://pyline.readthedocs.org/en/latest .. _Travis-CI: https://travis-ci.org/westurner/pyline
Pyline is a grep-like, sed-like, awk-like command-line tool for line-based text processing in Python.
.. contents::
original pyline recipe
_str.split
_ by an optional delimiter str (-F
, --input-delim
)Python regex
_ (-r
, --regex
, -R
, --regex-options
)txt
, csv
, tsv
, json
, html
(-O csv
, --output-filetype=csv
)-O checkbox
, --output-filetype=checkbox
)-s
, --sort-asc
; -S
, --sort-desc
)path.py <https://pypi.python.org/pypi/path.py>
__
(or pathlib
_) objects from each line (-p
,
--path-tools
)namedtuples
, iterators
yield
-ing generators
_optparse
_ argument parsing (-h
, --help
)cookiecutter-pypackage
_ project templating.. _path.py: https://pypi.python.org/pypi/path.py
.. _str.split: https://docs.python.org/2/library/stdtypes.html#str.split
.. _Python regex: https://docs.python.org/2/library/re.html
.. _pathlib: https://pypi.python.org/pypi/pathlib
.. _namedtuples: https://docs.python.org/2/library/collections.html#collections.namedtuple
.. _iterators: https://docs.python.org/2/howto/functional.html#iterators
.. _generators: https://docs.python.org/2/howto/functional.html#generators
.. _optparse: https://docs.python.org/2/library/optparse.html
.. _cookiecutter-pypackage: https://github.com/audreyr/cookiecutter-pypackage
Somewhat unsurprisingly, I found the original pyline recipe
_
while searching for "python grep sed"
(see AUTHORS.rst
and LICENSE.psf
).
I added an option for setting p = Path(line)
in the eval
/compile
command context and added it to my dotfiles <https://github.com/westurner/dotfiles/commits/master/src/dotfiles/pyline.py>
_
; where it grew tests and an optparse.OptionParser
; and is now
promoted to a GitHub
_ project with ReadTheDocs
_ documentation,
tests with tox and Travis-CI
, and a setup.py for PyPi
.
.. _original Pyline recipe: https://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/ .. _eval: https://docs.python.org/2/library/functions.html#eval .. _compile: https://docs.python.org/2/library/functions.html#compile .. _MapReduce: https://en.wikipedia.org/wiki/MapReduce
Pyline is an ordered MapReduce
_ tool:
Input Readers:
* stdin (default)
* file (codecs.open(file, 'r', encoding='utf-8')
)
Map Functions:
* Python module imports (-m os
)
* Python regex pattern (-r '\(.*\)'
)
* path library (p
from --pathpy
OR --pathlib
)
* Python codeobj eval output transform:
.. code:: bash
ls | pyline -m os 'line and os.path.abspath(line.strip())'
ls | pyline -r '\(.*\)' 'rgx and (rgx.group(0), rgx.group(1)) or line'
ls | pyline -p 'p and p.abspath() or ("# ".format(line))'
# With an extra outer loop to bind variables in
# (because (_p = p.abspath(); <codeobj>) does not work)
find $PWD | pyline --pathpy -m os -m collections --input-delim='/' \
'p and [collections.OrderedDict((
("p", p),
("_p", _p),
("_p.split()", str(_p).split(os.path.sep)),
("line.rstrip().split()", line.rstrip().split(os.path.sep)),
("l.split()", l.split(os.path.sep)),
("words", words),
("w", w)))
for _p in [p.abspath()]][0]' \
-O json
Partition Function: None
Compare Function:
Result(collections.namedtuple).__cmp__
Reduce Functions:
bool()
, sorted()
Output Writers:
ResultWriter
classes
.. code:: bash
pyline -O csv
pyline -O tsv
pyline -O json
Install from PyPi
_::
pip install pyline
Install from GitHub
_ as editable (add a pyline.pth
in site-packages
)::
pip install -e git+https://github.com/westurner/pyline#egg=pyline
Print help::
pyline --help
Process::
# Print every line (null transform)
cat ~/.bashrc | pyline line
cat ~/.bashrc | pyline l
# Number every line
cat ~/.bashrc | pyline -n l
# Print every word (str.split(input-delim=None))
cat ~/.bashrc | pyline words
cat ~/.bashrc | pyline w
# Split into words and print (default: tab separated)
cat ~/.bashrc | pyline 'len(w) >= 2 and w[1] or "?"'
# Select the last word, dropping lines with no words
pyline -f ~/.bashrc 'w[-1:]'
# Regex matching with groups
cat ~/.bashrc | pyline -n -r '^#(.*)' 'rgx and rgx.group()'
cat ~/.bashrc | pyline -n -r '^#(.*)'
## Original Examples
# Print out the first 20 characters of every line
tail access_log | pyline "line[:20]"
# Print just the URLs in the access log (seventh "word" in the line)
tail access_log | pyline "words[6]"
Work with paths and files::
# List current directory files larger than 1 Kb
ls | pyline -m os \
"os.path.isfile(line) and os.stat(line).st_size > 1024 and line"
# List current directory files larger than 1 Kb
#pip install path.py
ls | pyline -p 'p and p.size > 1024 and line'
https://pyline.readthedocs.org/en/latest/
Python Software License <https://github.com/westurner/pyline/blob/master/LICENSE.psf>
_
.
release/0.3.20 (2020-10-02 20:51:19 -0400) ++++++++++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.19..release/0.3.20
v0.3.19 (2020-10-02 20:44:25 -0400) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.18..v0.3.19
v0.3.18 (2020-10-02 20:27:08 -0400) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.17..v0.3.18
v0.3.17 (2018-12-23 14:41:45 -0500) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.16..v0.3.17
v0.3.16 (2016-07-22 11:42:57 -0500) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.15..v0.3.16
v0.3.15 (2016-07-22 11:34:56 -0500) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.14..v0.3.15
v0.3.14 (2016-07-22 11:27:03 -0500) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.13..v0.3.14
v0.3.13 (2016-07-22 11:16:44 -0500) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.12..v0.3.13
v0.3.12 (2016-02-16 16:07:18 -0600) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.11..v0.3.12
v0.3.11 (2016-02-14 22:29:55 -0600) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.10..v0.3.11
v0.3.10 (2016-02-14 21:56:36 -0600) +++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.9..v0.3.10
v0.3.9 (2016-02-14 17:58:36 -0600) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.8..v0.3.9
v0.3.8 (2016-02-14 17:34:08 -0600) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.7..v0.3.8
v0.3.7 (2016-02-12 20:04:39 -0600) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.6..v0.3.7
v0.3.6 (2015-12-21 04:17:23 -0600) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.5..v0.3.6
v0.3.5 (2015-05-24 20:58:39 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.4..v0.3.5
v0.3.4 (2015-04-25 06:48:47 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.3..v0.3.4
v0.3.3 (2015-04-25 06:43:37 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.2..v0.3.3
v0.3.2 (2014-11-30 19:49:42 -0600) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.1..v0.3.2
v0.3.1 (2014-10-27 07:53:27 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.3.0..v0.3.1
v0.3.0 (2014-10-27 07:34:58 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.2.0..v0.3.0
v0.2.0 (2014-08-24 14:44:31 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.5..v0.2.0
v0.1.5 (2014-05-12 20:59:34 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.4..v0.1.5
v0.1.4 (2014-05-12 20:42:52 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.3..v0.1.4
v0.1.3 (2014-05-12 20:30:47 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.2..v0.1.3
v0.1.2 (2014-05-12 20:24:26 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.1..v0.1.2
v0.1.1 (2014-05-12 19:41:54 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' v0.1.0..v0.1.1
v0.1.0 (2014-05-12 04:03:15 -0500) ++++++++++++++++++++++++++++++++++ ::
git log --reverse --pretty=format:'* %s [%h]' b1303ba..v0.1.0
0.0.1 (Unreleased) +++++++++++++++++++ | Source: http://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/
FAQs
Pyline is a grep-like, sed-like, awk-like command-line tool for line-based text processing in Python.
We found that pyline demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.