5. Examples

5.1. Sort

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

5.2. Filter

$ spy -l -f 'len(pipe) == 4' < test.txt
this
file
five

5.3. 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)' "'{}: {}'.format(*pipe)" < test.txt
1: this
2: file
3: has
4: five
5: lines

5.4. Convert CSV to JSON

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