-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcsplit.sh
More file actions
126 lines (63 loc) · 1.48 KB
/
csplit.sh
File metadata and controls
126 lines (63 loc) · 1.48 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
## Split on Nth line
seq 10 | csplit - 4
head xx*
rm xx*
## Split on regexp
csplit -q purchases.txt '/t.*p/'
head xx*
csplit -q purchases.txt '%t.*p%'
cat xx00
csplit -q purchases.txt '/xyz/'
## Regexp offset
csplit -q purchases.txt '/t.*p/1'
head xx*
csplit -q purchases.txt '%t.*p%2'
cat xx00
csplit -q purchases.txt '/t.*p/-2'
head xx*
csplit -q purchases.txt '/t.*p/5'
csplit -q purchases.txt '/t.*p/-5'
## Repeat split
seq 10 | csplit -q - 4 '{1}'
head xx*
cat log.txt
csplit -q log.txt '%warning%' '{2}'
cat xx00
csplit -q purchases.txt '/paste\|powder/' '{*}'
head xx*
seq 10 | csplit -q - 4 '{2}'
csplit -q purchases.txt '/tea/' '{4}'
## Keep files on error
seq 7 | csplit -q - 4 '{*}'
ls xx*
seq 7 | csplit -qk - 4 '{*}'
head xx*
## Suppress matched lines
seq 5 | csplit -q --suppress-matched - 3
head xx*
rm xx*
seq 10 | csplit -q --suppress-matched - 4 '{1}'
head xx*
csplit -q --suppress-matched purchases.txt '/soap\|powder/' '{*}'
head xx*
seq 11 16 | csplit -q --suppress-matched - '/[35]/' '{1}'
head xx*
rm xx*
## Exclude empty files
csplit -q --suppress-matched purchases.txt '/coffee\|tea/' '{*}'
head xx*
csplit -qz --suppress-matched purchases.txt '/coffee\|tea/' '{*}'
head xx*
## Customize filenames
seq 4 | csplit -q -f'num_' - 3
head num_*
seq 4 | csplit -q -n1 - 3
ls xx*
rm xx*
seq 4 | csplit -q -n3 - 3
ls xx*
seq 100 | csplit -q -b'%02x' - 3 '{20}'
ls xx*
rm xx*
seq 20 | csplit -q -f'num_' -b'%d.txt' - 3 '{4}'
ls num_*