You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-i, --case-insensitive ignore case of pattern to match upper
26
-
and lowercase characters
27
-
--stdin process stdin as input
28
-
--once replace search term only one in a file
29
-
--once-remove-match replace search term only one in a file
30
-
and also don't keep matching lines (for
31
-
line and lineinfile mode)
32
-
--regex treat pattern as regex
33
-
--regex-backrefs enable backreferences in replace term
34
-
--regex-posix parse regex term as POSIX regex
35
-
--path= use files in this path
36
-
--path-pattern= file pattern (* for wildcard, only
37
-
basename of file)
38
-
--path-regex= file pattern (regex, full path)
39
-
--ignore-empty ignore empty file list, otherwise this
40
-
will result in an error
41
-
-v, --verbose verbose mode
42
-
--dry-run dry run mode
43
-
-V, --version show version and exit
44
-
-h, --help show this help message
18
+
-m, --mode=[replace|line|lineinfile|template] replacement mode - replace: replace match with term; line: replace line with term; lineinfile: replace line with
19
+
term or if not found append to term to file; template: parse content as golang template, search value have to
20
+
start uppercase (default: replace)
21
+
-s, --search= search term
22
+
-r, --replace= replacement term
23
+
-i, --case-insensitive ignore case of pattern to match upper and lowercase characters
24
+
--stdin process stdin as input
25
+
--once replace search term only one in a file
26
+
--once-remove-match replace search term only one in a file and also don't keep matching lines (for line and lineinfile mode)
27
+
--regex treat pattern as regex
28
+
--regex-backrefs enable backreferences in replace term
29
+
--regex-posix parse regex term as POSIX regex
30
+
--path= use files in this path
31
+
--path-pattern= file pattern (* for wildcard, only basename of file)
32
+
--path-regex= file pattern (regex, full path)
33
+
--ignore-empty ignore empty file list, otherwise this will result in an error
| replace | Replace search term inside one line with replacement. |
50
-
| line | Replace line (if matched term is inside) with replacement. |
51
-
| lineinfile | Replace line (if matched term is inside) with replacement. If no match is found in the whole file the line will be appended to the bottom of the file. |
| replace | Replace search term inside one line with replacement. |
43
+
| line | Replace line (if matched term is inside) with replacement. |
44
+
| lineinfile | Replace line (if matched term is inside) with replacement. If no match is found in the whole file the line will be appended to the bottom of the file. |
45
+
| template | Parse content as [golang template](https://golang.org/pkg/text/template/), arguments are available via `{{.Arg.Name}}` or environment vars via `{{.Env.Name}}`|
Copy file name to clipboardExpand all lines: goreplace.go
+108-5Lines changed: 108 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ import (
11
11
"os"
12
12
"strings"
13
13
"regexp"
14
+
"text/template"
14
15
flags "github.com/jessevdk/go-flags"
15
16
)
16
17
@@ -36,11 +37,17 @@ type fileitem struct {
36
37
Pathstring
37
38
}
38
39
40
+
typetemplateDatastruct {
41
+
Argmap[string]string
42
+
Envmap[string]string
43
+
}
44
+
39
45
varoptsstruct {
40
-
Modestring`short:"m" long:"mode" description:"replacement mode - replace: replace match with term; line: replace line with term; lineinfile: replace line with term or if not found append to term to file" default:"replace" choice:"replace" choice:"line" choice:"lineinfile"`
46
+
Modestring`short:"m" long:"mode" description:"replacement mode - replace: replace match with term; line: replace line with term; lineinfile: replace line with term or if not found append to term to file; template: parse content as golang template, search value have to start uppercase" default:"replace" choice:"replace" choice:"line" choice:"lineinfile" choice:"template"`
0 commit comments