@@ -24,25 +24,25 @@ If you're already familiar with shell scripting and the Unix toolset, here is a
24
24
| ------------------ | ------------------- |
25
25
| (any program name) | [ ` Exec() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Exec ) |
26
26
| ` [ -f FILE ] ` | [ ` IfExists() ` ] ( https://pkg.go.dev/github.com/bitfield/script#IfExists ) |
27
- | ` > ` | [ ` WriteFile() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Writefile ) |
28
- | ` >> ` | [ ` AppendFile() ` ] ( https://pkg.go.dev/github.com/bitfield/script#AppendFile ) |
27
+ | ` > ` | [ ` WriteFile() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe.WriteFile ) |
28
+ | ` >> ` | [ ` AppendFile() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. AppendFile ) |
29
29
| ` $* ` | [ ` Args() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Args ) |
30
- | ` basename ` | [ ` Basename() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Basename ) |
31
- | ` cat ` | [ ` File() ` ] ( https://pkg.go.dev/github.com/bitfield/script#File ) / [ ` Concat() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Concat ) |
32
- | ` cut ` | [ ` Column() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Column ) |
33
- | ` dirname ` | [ ` Dirname() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Dirname ) |
30
+ | ` basename ` | [ ` Basename() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Basename ) |
31
+ | ` cat ` | [ ` File() ` ] ( https://pkg.go.dev/github.com/bitfield/script#File ) / [ ` Concat() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Concat ) |
32
+ | ` cut ` | [ ` Column() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Column ) |
33
+ | ` dirname ` | [ ` Dirname() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Dirname ) |
34
34
| ` echo ` | [ ` Echo() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Echo ) |
35
- | ` grep ` | [ ` Match() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Match ) / [ ` MatchRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#MatchRegexp ) |
36
- | ` grep -v ` | [ ` Reject() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Reject ) / [ ` RejectRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#RejectRegexp ) |
37
- | ` head ` | [ ` First() ` ] ( https://pkg.go.dev/github.com/bitfield/script#First ) |
35
+ | ` grep ` | [ ` Match() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Match ) / [ ` MatchRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. MatchRegexp ) |
36
+ | ` grep -v ` | [ ` Reject() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Reject ) / [ ` RejectRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. RejectRegexp ) |
37
+ | ` head ` | [ ` First() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. First ) |
38
38
| ` find -type f ` | [ ` FindFiles ` ] ( https://pkg.go.dev/github.com/bitfield/script#FindFiles ) |
39
39
| ` ls ` | [ ` ListFiles() ` ] ( https://pkg.go.dev/github.com/bitfield/script#ListFiles ) |
40
- | ` sed ` | [ ` Replace() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Replace ) / [ ` ReplaceRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#ReplaceRegexp ) |
41
- | ` sha256sum ` | [ ` SHA256Sum() ` ] ( https://pkg.go.dev/github.com/bitfield/script#SHA256Sum ) / [ ` SHA256Sums() ` ] ( https://pkg.go.dev/github.com/bitfield/script#SHA256sums ) |
42
- | ` tail ` | [ ` Last() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Last ) |
43
- | ` uniq -c ` | [ ` Freq() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Freq ) |
44
- | ` wc -l ` | [ ` CountLines() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Countlines ) |
45
- | ` xargs ` | [ ` ExecForEach() ` ] ( https://pkg.go.dev/github.com/bitfield/script#ExecForEach ) |
40
+ | ` sed ` | [ ` Replace() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Replace ) / [ ` ReplaceRegexp() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. ReplaceRegexp ) |
41
+ | ` sha256sum ` | [ ` SHA256Sum() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. SHA256Sum ) / [ ` SHA256Sums() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe.SHA256Sums ) |
42
+ | ` tail ` | [ ` Last() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Last ) |
43
+ | ` uniq -c ` | [ ` Freq() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Freq ) |
44
+ | ` wc -l ` | [ ` CountLines() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe.CountLines ) |
45
+ | ` xargs ` | [ ` ExecForEach() ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. ExecForEach ) |
46
46
47
47
# Some examples
48
48
@@ -154,41 +154,41 @@ Filters are methods on an existing pipe that also return a pipe, allowing you to
154
154
155
155
| Filter | Results |
156
156
| -------- | ------------- |
157
- | [ ` Basename ` ] ( https://pkg.go.dev/github.com/bitfield/script#Basename ) | removes leading path components from each line, leaving only the filename |
158
- | [ ` Column ` ] ( https://pkg.go.dev/github.com/bitfield/script#Column ) | Nth column of input |
159
- | [ ` Concat ` ] ( https://pkg.go.dev/github.com/bitfield/script#Concat ) | contents of multiple files |
160
- | [ ` Dirname ` ] ( https://pkg.go.dev/github.com/bitfield/script#Dirname ) | removes filename from each line, leaving only leading path components |
161
- | [ ` EachLine ` ] ( https://pkg.go.dev/github.com/bitfield/script#EachLine ) | user-supplied function |
162
- | [ ` Echo ` ] ( https://pkg.go.dev/github.com/bitfield/script#Echo ) | all input replaced by given string |
163
- | [ ` Exec ` ] ( https://pkg.go.dev/github.com/bitfield/script#Exec ) | filtered through external command |
164
- | [ ` ExecForEach ` ] ( https://pkg.go.dev/github.com/bitfield/script#ExecForEach ) | execute given command template for each line of input |
165
- | [ ` First ` ] ( https://pkg.go.dev/github.com/bitfield/script#First ) | first N lines |
166
- | [ ` Freq ` ] ( https://pkg.go.dev/github.com/bitfield/script#Freq ) | frequency count of unique input lines, most frequent first |
167
- | [ ` Join ` ] ( https://pkg.go.dev/github.com/bitfield/script#Join ) | replace all newlines with spaces |
168
- | [ ` Last ` ] ( https://pkg.go.dev/github.com/bitfield/script#Last ) | last N lines |
169
- | [ ` Match ` ] ( https://pkg.go.dev/github.com/bitfield/script#Match ) | matching lines |
170
- | [ ` MatchRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#MatchRegexp ) | matching lines |
171
- | [ ` Reject ` ] ( https://pkg.go.dev/github.com/bitfield/script#Reject ) | non-matching lines |
172
- | [ ` RejectRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#RejectRegexp ) | non-matching lines |
173
- | [ ` Replace ` ] ( https://pkg.go.dev/github.com/bitfield/script#Replace ) | matching lines replaced with string |
174
- | [ ` ReplaceRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#ReplaceRegexp ) | matching lines replaced with string |
175
- | [ ` SHA256Sums ` ] ( https://pkg.go.dev/github.com/bitfield/script#SHA256Sums ) | SHA-256 hashes of each listed file |
157
+ | [ ` Basename ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Basename ) | removes leading path components from each line, leaving only the filename |
158
+ | [ ` Column ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Column ) | Nth column of input |
159
+ | [ ` Concat ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Concat ) | contents of multiple files |
160
+ | [ ` Dirname ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Dirname ) | removes filename from each line, leaving only leading path components |
161
+ | [ ` EachLine ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. EachLine ) | user-supplied function |
162
+ | [ ` Echo ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Echo ) | all input replaced by given string |
163
+ | [ ` Exec ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Exec ) | filtered through external command |
164
+ | [ ` ExecForEach ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. ExecForEach ) | execute given command template for each line of input |
165
+ | [ ` First ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. First ) | first N lines |
166
+ | [ ` Freq ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Freq ) | frequency count of unique input lines, most frequent first |
167
+ | [ ` Join ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Join ) | replace all newlines with spaces |
168
+ | [ ` Last ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Last ) | last N lines |
169
+ | [ ` Match ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Match ) | matching lines |
170
+ | [ ` MatchRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. MatchRegexp ) | matching lines |
171
+ | [ ` Reject ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Reject ) | non-matching lines |
172
+ | [ ` RejectRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. RejectRegexp ) | non-matching lines |
173
+ | [ ` Replace ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Replace ) | matching lines replaced with string |
174
+ | [ ` ReplaceRegexp ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. ReplaceRegexp ) | matching lines replaced with string |
175
+ | [ ` SHA256Sums ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. SHA256Sums ) | SHA-256 hashes of each listed file |
176
176
177
177
## Sinks
178
178
179
179
Sinks are methods that return some data from a pipe, ending the pipeline and extracting its full contents in a specified way:
180
180
181
181
| Sink | Destination | Results |
182
182
| ---- | ----------- | ------- |
183
- | [ ` AppendFile ` ] ( https://pkg.go.dev/github.com/bitfield/script#AppendFile ) | appended to file, creating if it exists | bytes written, error |
184
- | [ ` Bytes ` ] ( https://pkg.go.dev/github.com/bitfield/script#Bytes ) | | data as ` []byte ` , error
185
- | [ ` CountLines ` ] ( https://pkg.go.dev/github.com/bitfield/script#CountLines ) | | number of lines, error |
186
- | [ ` Read ` ] ( https://pkg.go.dev/github.com/bitfield/script#Read ) | given ` []byte ` | bytes read, error |
187
- | [ ` SHA256Sum ` ] ( https://pkg.go.dev/github.com/bitfield/script#SHA256Sum ) | | SHA-256 hash, error |
188
- | [ ` Slice ` ] ( https://pkg.go.dev/github.com/bitfield/script#Slice ) | | data as ` []string ` , error |
189
- | [ ` Stdout ` ] ( https://pkg.go.dev/github.com/bitfield/script#Stdout ) | standard output | bytes written, error |
190
- | [ ` String ` ] ( https://pkg.go.dev/github.com/bitfield/script#String ) | | data as ` string ` , error |
191
- | [ ` WriteFile ` ] ( https://pkg.go.dev/github.com/bitfield/script#WriteFile ) | specified file, truncating if it exists | bytes written, error |
183
+ | [ ` AppendFile ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. AppendFile ) | appended to file, creating if it exists | bytes written, error |
184
+ | [ ` Bytes ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Bytes ) | | data as ` []byte ` , error
185
+ | [ ` CountLines ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. CountLines ) | | number of lines, error |
186
+ | [ ` Read ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Read ) | given ` []byte ` | bytes read, error |
187
+ | [ ` SHA256Sum ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. SHA256Sum ) | | SHA-256 hash, error |
188
+ | [ ` Slice ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Slice ) | | data as ` []string ` , error |
189
+ | [ ` Stdout ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. Stdout ) | standard output | bytes written, error |
190
+ | [ ` String ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. String ) | | data as ` string ` , error |
191
+ | [ ` WriteFile ` ] ( https://pkg.go.dev/github.com/bitfield/script#Pipe. WriteFile ) | specified file, truncating if it exists | bytes written, error |
192
192
193
193
## Examples
194
194
0 commit comments