replace_string

package
v0.77.0-dev-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "replace-string",
	Short:   "Replace string in file (like sed)",
	Aliases: []string{"rs"},
	Args:    cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		inputBytes, err := os.ReadFile(FlagInputFilePath)
		if err != nil {
			log.Fatalln(err)
		}

		input := string(inputBytes)
		output := strings.Replace(input, FlagFindString, FlagReplacementString, -1)

		if FlagOutputFilePath == "" {
			fmt.Println(output)
		} else {
			err = os.WriteFile(FlagOutputFilePath, []byte(output), 0644)
			if err != nil {
				log.Fatalln(err)
			}
		}
	},
}
View Source
var FlagFindString string
View Source
var FlagInputFilePath string
View Source
var FlagOutputFilePath string
View Source
var FlagReplacementString string

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL