-
Notifications
You must be signed in to change notification settings - Fork 0
/
srek.1
214 lines (214 loc) · 4.32 KB
/
srek.1
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
.TH SREK 1 srek\-VERSION
.SH NAME
srek \- Structural RegEx Kit
.SH SYNOPSIS
\fBsrek\fR [\fIOPTION\fR]... \fICOMMAND-LINE\fR [\fIFILE\fR]...
.SH DESCRIPTION
\fIsrek\fR is a sed-like stream editor based on Rob Pike's structural regular expressions. Its main distinction from
.BR sed (1)
is that the user is not forced to process the input line-wise. Instead, the text can be partitioned using arbitrary regular expressions (see \fBx\fR command under the COMMAND SYNOPSIS).
.P
The text processing and manipulation language of
.I srek
can be used interactively, in pipelines or called from other unix tools such as
.BR vi (1).
.SH OPTIONS
.TP
.B \-B, --basic-regexp
Use POSIX Basic regular expressions
.TP
.B \-E, --extended-regexp
Use POSIX Extended regular expressions (this is the default)
.TP
.B \-f, --file=<file>
Read COMMAND-LINE from <file>
.TP
.B \-h, --help
Display help, then exit
.TP
.B \-i, --ignorecase
Ignore case when matching regex
.TP
.B \-n, --quiet
Do not put an implicit print command at the end
.TP
.B \-N, --reg-newline
Match-any-character operators don't match a newline
.TP
.B \-v, --version
Display version, then exit
.SH COMMAND SYNOPSIS
.I COMMAND-LINE
may contain a list of commands separated by optional whitespaces:
.TP
\fBx\fR/\fIregexp\fR/
.RI
Extract matches from input to a set of selections
.RI
.TP
\fBy\fR/\fIregexp\fR/
.RI
Like \fBx\fR, but extract the non-matching parts instead
.RI
.TP
\fBg\fR/\fIregexp\fR/
.RI
Filter selections with \fIregexp\fR
.RI
.TP
\fBv\fR/\fIregexp\fR/
.RI
Like \fBg\fR, but keep the non-matching selections instead
.RI
.TP
\fB~\fR
.RI
Flip selections (everything selected becomes unselected and vice versa)
.RI
.TP
\fBL\fR
.RI
Extract lines, shorthand for x/[^\\n]*\\n/
.RI
.TP
\fBu\fR
.RI
Undo all selections
.RI
.TP
\fBp\fR
.RI
Print all selection to \fIstdout\fR
.RI
.TP
\fBd\fR
.RI
Delete selected text, selection resets
.RI
.TP
\fBc\fR/\fIreplacement\fR/
.RI
Replace each selection with \fIreplacement\fR, selection resets
.RI
.TP
\fBs\fR/\fIregexp\fR/\fIreplacement\fR/
.RI
Replace matching parts of each selection with \fIreplacement\fR
.RI
.TP
\fBi\fR/\fIprefix\fR/
.RI
Prefix selections with \fIprefix\fR, shorthand for s/^/text/
.RI
.TP
\fBa\fR/\fIsuffix\fR/
.RI
Suffix selections with \fIsuffix\fR, shorthand for s/$/text/
.RI
.TP
\fBS\fR/\fIprefix\fR/\fIsuffix\fR/
.RI
Surround selections, shorthand for i/prefix/a/suffix/
.RI
.TP
\fBr\fR/\fIfile\fR/
.RI
Replace selections with contents read from \fIfile\fR
.RI
.TP
\fBR\fR/\fIfile\fR/
.RI
Like \fBr\fR, but append instead
.RI
.TP
\fBw\fR/\fIfile\fR/\fIsep\fR/
.RI
Write selections to \fIfile\fR, each separated by \fIsep\fR
.RI
.TP
\fBW\fR/\fIfile\fR/\fIsep\fR/
.RI
Like \fBw\fR, but append to \fIfile\fR instead
.RI
.TP
\fB!\fR/\fIcmd\fR/
.RI
Run \fIcmd\fR once for each selection
.RI
.TP
\fB<\fR/\fIcmd\fR/
.RI
Run \fIcmd\fR once, and replace selections with its \fIstdout\fR
.RI
.TP
\fB>\fR/\fIcmd\fR/
.RI
Run \fIcmd\fR once for each selection by passing the selection to its \fIstdin\fR
.RI
.TP
\fB|\fR/\fIcmd\fR/
.RI
Run \fIcmd\fR on each selection by taking it as \fIstdin\fR and replacing it with \fIstdout\fR
.RI
.TP
\fBt\fR/\fIcmd\fR/
.RI
Keep only those selections for which \fIcmd\fR returned with success (zero)
.RI
.TP
\fBT\fR/\fIcmd\fR/
.RI
Keep only those selections for which \fIcmd\fR returned with error (non-zero)
.RI
.P
\fBNote:\fR \fIcmd\fR must be a valid shell command
.TP
\fB#\fR\fIcomment\fR
.RI
Comment till next newline
.RI
.SH EXAMPLES
.TP
srek 'x/#[^\\n]*\\n/ d'
.RI
Delete Python comments
.RI
.TP
srek 'x/#[^\\n]*\\n/ w/commented.txt/\\n/'
.RI
Output comments separated by newlines to a new file
.RI
.TP
srek 'y/#[^\\n]*\\n/ w/not_commented.txt/\\n/'
.RI
Same, except now output the not commented parts
.RI
.TP
srek 'x/[a-zA-Z]+:/ S/**/**/ u'
.RI
Turn words followed by colons to bold for Markdown
.RI
.TP
srek 'x/todo|readme|license/ |/tr a-z A-Z/'
.RI
Turn some words to uppercase
.RI
.TP
srek 's/ +/ /'
.RI
Condense consecutive spaces to a single one
.RI
.SH SEE ALSO
.BR ed (1),
.BR ex (1),
.BR sed (1),
.BR grep (1)
.SH BUGS
Please report bugs by creating issues at
.BR <https://github.com/Seeker04/srek/issues>
.SH AUTHOR
srek was created by Barnabás Zahorán <[email protected]>.
.P
For a comprehensive list of contributors, please visit \fB<https://github.com/seeker04/srek>\fR.
.SH COPYRIGHT
MIT License, Copyright (c) 2022-2024 Barnabás Zahorán, see LICENSE