Simplify and automate text manipulation with NimbleText

NimbleText is a useful tool that has been in my toolset for many years now. On the website, NimbleText is described as a “text manipulation and code generation tool (…) that magnifies your ability to perform incredible feats of text and data wrangling”. I agree with this statement and I don’t think it’s an exaggeration. And best of all, it’s free! There is a premium edition which unlocks all features and costs around $20. There is also a fiddle-like version available.

When you are developing you often need to apply a certain template numerous times with only a few details changed. Examples of this could be:

  • Creation of files where most of the name is shared
  • Code generation in which most of the code is the same
  • Replace a word in a number of sentences

When there is a pattern that needs to be applied various times, NimbleText could save you quite a lot of time, frustrations and possibly, bugs.

This is how the application looks like when you fire it up:

Nimbletext default

I admit it looks slightly outdated but it works just fine. There is even a command-line available, which I haven’t really used that often (it is part of the premium version). When you discover you need to do the same action in bulk then you could partially automate this with a command-line function.

The application is divided into three sections:

  • The first section contains the data that is to be manipulated.
  • The second section contains the operation that will be executed on every row in the first section
  • The third section shows the result of section 2’s application on the first section

Let’s see this in action with a couple of examples.

Basic text formatting

Placeholders

Assume we want to create the same sentence a number of times but with a different name. With placeholders this is a trivial task:

Nimbletext default

The magic key here is $0. You can have as many placeholders as you want (the order in which they are placed in the substitute doesn’t matter):

Nimbletext default

How does NimbleText know where the first placeholder ends and the second one starts? The answer is delimiters. By default, each row is separated by a new line and a column is separated by comma. In the results section, you can see that this is configurable:

Nimbletext default

These delimiters slice and dice your data so it can distinguish between rows and columns. The result of the last example would look like this:

Col 1 Col 2
Row 1 Jane pigeon
Row 2 John duck
Row 3 Hank man walking his dog

Depending on your data, the defaults could be just right but sometimes you may want to change this.
For instance, your rows could be delimited with comma’s:

nimbletext_005

If you are at all familiar with programming languages, this is basically string.format applied in a loop. The nice thing is that this is an ad-hoc tool. If you quickly (and temporarily) need to copy/paste a certain text with a few details changed, then this is the perfect tool.

Row

There is another keyword which could be useful when you want to paste the entire row as the variable: $row

Nimbletext default

A very common case is to trim empty lines. Using the $row keyword does exactly that.

Once and each

Another neat set of keywords are $ONCE and $EACH. Their use is fairly self-explanatory. The text between $ONCE and $EACH will be exactly outputted once, regardless of the input data. $EACH restores the original behavior and outputs the text for every row in the input section.

Nimbletext default

The other keywords are listed here in detail.

Text manipulation

NimbleText also offers a number of string manipulations that can be performed on the text, such as upper- and lowercase, replace, reverse, etc. You can insert them manually or you can use the functions menu. Here’s an example that converts the first placeholder into its uppercase version:

Nimbletext default

You can even chain functions:

Nimbletext default

Note that are you not limited to manipulating the variables:

Nimbletext default

All the built-in functions are listed here.

Filtering

In the premium edition of NimbleText you get access to the ‘Where’ clause. Using JavaScript’s syntax you can write expressions like this:

Nimbletext default

Date formatting

There are many libraries that have the same goal of making date formatting easier. Given that much of the syntax in NimbleText is JavaScript, it should be no wonder that the date formatting is also based on Javascript’s date notation.

Nimbletext default

Command-line

I am glad to report that everything that can be done in the GUI can also be done with the command-line tool, or if you’re feeling fancy with PowerShell.

Without reading the docs, you can probably understand what this command tries to achieve:

NimbleText.exe  
--inputdatafile input.txt
--where "$0 !== 'Jane'"
--pattern "<% $0.toUpperCase() %> went to the park"
--outputfile output.txt

Just like any other command-line tool, a comprehensive documentation is key. Fortunately this is the case with NimbleText. For the complete reference, follow this link.

Input

With the command line you will probably want to resort to an external file such as a .txt or .csv file. You can paste the data into the command-line if you wanted to using the -d flag. Otherwise you use the -i flag along with the file name.

Pattern

Same principle for the patterns. You can store them in a separate file (-p) or you could type it in the console (-f).

Output

If you want the output to be piped in a separate file, you can use the -o option along with the name of the file.

Separators

Just like in the GUI you can change the row- and column delimiters. The commands are -r for rows and -c for columns.

There are a few other options but I found these are the ones I have used so far. When in doubt, consult the docs or use the -help flag.

Conclusion

NimbleText is a fantastic little but powerful tool that makes repetitive work less boring and minimizes risk of mistakes in the act of copy/pasting large amounts of data. It is lightweight, fast, easy to use and it is free. Considering all of this, this should be in any developers toolkit.

Leave a Reply