News for hackers. Stuff that matters.
Re:Go Replace - simple and fast search and replace tool for ... by JoeAcchino on Wednesday May 22, 2013 @06:52AM (#5749941)

    find ~/my/docs/ -type f -name '*.txt' -exec sed -i.bak 's/inheritance/composition/g' {} +
This will search all files ending in `.txt` and will exec `sed 's/inheritance/composition/g'` on it. Sed modifies files in-place and saves a backup file with .bak extension (-i.bak) and is called the minimum necessary times (-exec +).

My best advice to someone using the command line is to learn `find` + `xargs` or, even better, `find` + `parallel`.

Re:Go Replace - simple and fast search and replace tool for ... by gladimdim on Wednesday May 22, 2013 @06:56AM (#5749946)
Compare with "gr what-is-it -r here-you-go". I do not have to remember all that argument hell.
Re:Go Replace - simple and fast search and replace tool for ... by dhamidi on Wednesday May 22, 2013 @07:55AM (#5750135)
Probably slower than the go version, but more flexible since you have more over the files processed.

        # bash
	# find/replace
	function fr {
		local pattern=$1
		local replacement=$2
		local program

		if [[ -z "$replacement" ]]
		then
			program="grep $pattern"
		else
			program="sed -i s/$pattern/$replacement/g"
		fi

		while read line
		do
			$program "$line"
		done
	}

	# usage
	find . | fr find-this
	find . | fr replace-this with-that
Re:Go Replace - simple and fast search and replace tool for ... by anonymouz on Wednesday May 22, 2013 @07:52AM (#5750123)
Well, one can write an one-line shell alias (or script) instead of reinventing the wheel by rewriting the whole thing anew in Go. (Which is certainly good as learning experience for Go, but the end result is easier to achieve with the shell)
Re:Go Replace - simple and fast search and replace tool for ... by piranha on Wednesday May 22, 2013 @08:17AM (#5750219)
When you start adding coloring, nice output, .hg/.gitignore support, it becomes just a big mess. Been there, done that.
Re:Go Replace - simple and fast search and replace tool for ... by andreypopp on Wednesday May 22, 2013 @10:22AM (#5751002)
coloring is already supported by grep, .hg/.gitignore support is just a few lines
Re:Go Replace - simple and fast search and replace tool for ... by piranha on Wednesday May 22, 2013 @10:37AM (#5751133)
Just do it then.
Re:Go Replace - simple and fast search and replace tool for ... by peterwwillis on Wednesday May 22, 2013 @09:49AM (#5750776)
A C wrapper around `sed -e "s/what-is-it/here-you-go/" would be a little more efficient, and a lot simpler. Reinventing the wheel is bad for X+Y+Z reasons, where X, Y and Z are the bugs, options, and features in the last wheel.