solovyov.net

Go Replace!

2 min read · programming, go

Once upon a time two and something years ago I decided to check out Go to learn if it’s easy to write applications using it and how good (or bad) result is. Idea for a first application popped up immediately - my beloved Python has somewhat slowish startup, so I decided to rewrite sr, which I used a lot, in Go.

That’s how Go Replace was born (I should’ve written this post two years ago, frankly). Obviously, searching in files is a problem solved long time ago - you could use find + grep, or grep + shell glob expansion, or ack, or the_silver_searcher, but none of them can perform replacement. And this point was always a pain for me, since rewriting command line in find + sed or xargs + sed is not the most pleasant task. But gr (a short name I’ve chosen) can, and that’s the whole deal:

# searching
$ gr what-is-it
# and replacing
$ gr what-is-it -r here-you-go

Press key up and add replacement line and here you go indeed!

Long story short: it’s easy to write in Go, applications are fast and beautiful. :) Other things being equal it’s usually around 1.5x-2x slower than GNU grep (it’s not recent test but I’m not really worried about such speed difference). But it uses patterns from .hgignore and .gitignore of your repository to skip files and skips binaries, so usually it’s faster. :) And you get normal regexp syntax instead of POSIX’ kind of grep/sed.

Plus you don’t need to compile anything! Just download and enjoy. It’s just a binary and has no dependencies.

If you like what you read — subscribe to my Twitter, I always post links to new posts there. Or, in case you're an old school person longing for an ancient technology, put a link to my RSS feed in your feed reader (it's actually Atom feed, but who cares).

Other recent posts

Server-Sent Events (SSE), but with POST
ngrok for the wicked, or expose your ports comfortably
PostgreSQL collation
History Snapshotting in TwinSpark
Code streaming: hundred ounces of nuances