Home Link

Hello, my name is Brett Terpstra, and it’s nice to meet you. Elegant solutions to complex problems. Curious?

Quick Tip: This command line trick is tops

Quick Tip: This command line trick is tops Tagged:
Sep 06, 2011 (166 days ago)

I just (accidentally) discovered the command tops while working in Terminal. I’m not seeing many of mentions of it (any) on the web, but it could be too early in the morning for me to form a coherent query. Regardless, I thought I’d give it a mention. The man page is quite complete, and has a succinct explanation of the command: tops - perform in-place substitutions on code.

It’s not just useful for code, though, it makes a great tool for batch modifications to any text file(s). With an easy-to-grok syntax, it does in a few words what I usually do in three or more piped oneliners (grep, awk, sed, etc.). There’s a replacemethod option specifically for replacing Objective-C-style method names, which leads me to believe that this is an OS X-only tool, possibly only part of the Developer Tools. If anyone more familiar with this command has insight, I’d be curious.

Tops can read a script file with rules for search and replace, or take commands as arguments to process changes in a text file instantly. Simple example:

tops replace "Word" with "Markdown" writing.*

All instances of “Word” in all files with the name “writing” were just replaced with “Markdown.” Try it, it’s cool. The options go far beyond my simplistic example, but the more complex options are primarily specific to Objective-C. If this piques your curiosity anyway, spend some time with man tops.

3 Responses to “Quick Tip: This command line trick is tops”

  1. Quick Tip: This command line trick is tops http://t.co/58BIU8z [post]

  2. Scott Lee says:

    Sweet find! Thanks for sharing. I too found awk cumbersome and not very intuitive to use.

  3. […] Quick Tip: This Command Line Trick Is TOPS […]

Leave a Reply

Comments may use standard Markdown formatting


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Thanks for reading!

Entries (RSS) and Comments (RSS), or Subscribe by Email