Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 854 Bytes

examples.rst

File metadata and controls

70 lines (49 loc) · 854 Bytes

Examples

Sort

$ spy -mc sorted < test.txt
file
five
has
lines
this

Similarly:

$ spy -mc reversed < test.txt
lines
five
has
file
this

Filter

$ spy -l -fc 'len == 4' < test.txt
this
file
five

Enumerate

Naively:

$ spy -m "['{}: {}'.format(n, v) for n, v in enumerate(pipe, 1)]" < test.txt
1: this
2: file
3: has
4: five
5: lines

Taking advantage of spy piping:

$ spy -m 'enumerate(pipe, 1)' -i '{}: {}' < test.txt
1: this
2: file
3: has
4: five
5: lines

Convert CSV to JSON

$ spy -c csv.DictReader -c list -c json.dumps < thing.csv > thing.json