-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoink
executable file
·42 lines (36 loc) · 980 Bytes
/
joink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
"""Join k lines together with a space character.
Usage:
shell> cat inputfile
line1
line2
line3
line4
[...]
shell> joink 2 < inputfile
line1 line2
line3 line4
[...]
"""
# Dependencies:
# needs my waterworks library:
# https://github.com/dmcc/waterworks
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
from iterextras import batch
import argparse
import fileinput
import sys
parser = argparse.ArgumentParser()
parser.add_argument(
"filenames", metavar="F", type=str, nargs="*", help="Filenames to read from"
)
parser.add_argument("-s", "--separator", help="", default=" ")
parser.add_argument(
"-n", "--num-lines", help="How many lines to join", type=int, default=2
)
args = parser.parse_args()
for lines in batch(fileinput.input(files=args.filenames), batchsize=args.num_lines):
lines = [line.rstrip() for line in lines]
print(args.separator.join(lines))